Plotting a family of curves in mathematica

Click For Summary

Discussion Overview

The discussion focuses on plotting a family of curves in Mathematica, specifically for functions like sin(nx) for varying integer values of n. Participants explore methods for labeling these curves effectively on a single graph, considering both interactive and static presentation options.

Discussion Character

  • Technical explanation
  • Exploratory
  • Homework-related

Main Points Raised

  • One participant seeks a method to label curves corresponding to different integer values of n in a plot, expressing concern over the tediousness of manual labeling.
  • Another participant suggests using the Tooltip command to display function formulas on mouseover, although this may not meet the original poster's needs for exporting to PDF.
  • A different participant proposes using the PlotLegend option with a list of labels generated by StringForm to automatically label the curves for specific values of n.
  • The original poster confirms that the suggested PlotLegend method worked for their needs.

Areas of Agreement / Disagreement

Participants generally agree on the need for effective labeling methods for plotted curves, but there are differing opinions on the best approach, particularly regarding the use of interactive versus static labeling methods.

Contextual Notes

The discussion does not resolve the limitations of the Tooltip command for exporting graphs, nor does it address potential issues with the PlotLegend method in different contexts or with varying numbers of curves.

Who May Find This Useful

This discussion may be useful for Mathematica users looking to plot multiple functions and seeking efficient ways to label their graphs, particularly in the context of educational or presentation materials.

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.
 
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 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K