Plotting a family of curves in mathematica

muppet
Messages
602
Reaction score
0
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.
 
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 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K