Plotting a family of curves in mathematica

In summary, the conversation discusses the process of plotting a family of curves on a single graph, with each curve corresponding to a different value of an integer n. The command used for plotting and the issue of labeling the curves is mentioned. One solution suggested is to use the Tooltip command, but the person needs a different method in order to export the graph to a PDF file. Another solution is provided using the PlotLegend option from the PlotLegends package. The conversation concludes with confirmation that the solution worked.
  • #1
muppet
608
1
Hi all,

I'd like to plot a family of curves corresponding to different values of an integer n (eg. sin(nx) for n=1,2,3...) on a single graph, along with some kind of indication as to what value of n each curve corresponds to. I'm using the command
Plot[Evaluate@Table[Abs[P[-t, n]], {n, 3, 10}], {t, 0, 2}, AxesLabel -> {-t', Abs[P]}]
where P[x,n] is the nth function of x I'd like to plot.

Can anyone suggest a good way of labelling the curves? All the documentation I've read relating to e.g. plot legend seems to need you to put the labels in by hand, and not only would this be tedious to modify but I don't even presently know what colour curve corresponds to what value of n.

Thanks in advance.
 
Physics news on Phys.org
  • #2
You might have a look at the Tooltip command:
f[x_] := 1 - x;
g[x_] := x x;
Plot[Tooltip[{f[x], g[x], f[x]*g[x]}], {x, -1, 1}]
Which displays the Formula for the equation on mouseover for each function on the graph.
 
  • #3
Thanks for your reply. Unfortunately I really want to export my graph to a pdf file, so I need a more old-fashioned way of presenting the information...
 
  • #4
This should do the trick, just supply the PlotLegend Option a List:
Code:
Needs["PlotLegends`"]

f[x_, n_] := Sin[n x]
nmin = 1;
nmax = 3;

Plot[Evaluate@Table[Abs[f[x, n]], {n, nmin, nmax}], {x, 0, \[Pi]}, 
 AxesLabel -> {"x", "Abs[sin(n x)]"},
 PlotLegend -> [B]Table[StringForm["n=`1`", n], {n, nmin, nmax}][/B],
 LegendPosition -> {1, 0},
 LegendBorder -> None,
 LegendShadow -> None,
 LegendSize -> 0.5,
 ImageSize -> 400]
 
Last edited:
  • #5
That worked a treat, thanks!
 

1. How do I plot a family of curves in Mathematica?

To plot a family of curves in Mathematica, you can use the ParametricPlot function. This allows you to specify a set of parametric equations that describe the curve, and then plot them with different parameter values to create a family of curves.

2. Can I customize the appearance of the curves in the family plot?

Yes, you can customize the appearance of the curves in the family plot using the ParametricPlot function's options. For example, you can change the color, thickness, and style of the curves.

3. How do I add labels and legends to my family plot?

To add labels and legends to your family plot, you can use the PlotLabel and PlotLegends options in the ParametricPlot function. You can also use the Epilog option to add additional text or graphics to the plot.

4. Is it possible to plot multiple families of curves on the same plot?

Yes, you can plot multiple families of curves on the same plot by using the Show function. This allows you to combine multiple ParametricPlot functions into one plot.

5. Can I export my family plot as an image or a file?

Yes, you can export your family plot as an image or a file using the Export function. This allows you to save your plot in a variety of formats, such as PNG, JPG, or PDF.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
203
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
157
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Differential Equations
Replies
7
Views
334
Back
Top