Mathematica Plotting a family of curves in mathematica

AI Thread Summary
The discussion centers on plotting a family of curves for different integer values of n, specifically using the function sin(nx). The user initially struggles with labeling the curves in a way that is efficient and clear, as the standard documentation suggests manual labeling, which is cumbersome. A suggestion is made to use the Tooltip command for interactive labeling, but the user prefers a static solution for exporting to PDF. The solution provided involves using the PlotLegend option from the PlotLegends package, allowing for automated labeling of the curves based on the values of n. This method successfully addresses the user's needs, enabling clear labeling without manual input.
muppet
Messages
602
Reaction score
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
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.
 
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...
 
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:
That worked a treat, thanks!
 

Similar threads

Replies
1
Views
2K
Replies
1
Views
2K
Replies
4
Views
4K
Replies
1
Views
2K
Replies
3
Views
2K
Back
Top