Re: Adding identification marks to a Plot

• To: mathgroup at christensen.cybernetics.net
• Subject: [mg859] Re: [mg791] Adding identification marks to a Plot
• From: Allan Hayes <hay at haystack.demon.co.uk>
• Date: Wed, 26 Apr 1995 00:26:29 -0400

```In [mg791] Joseph McWilliams writes

> The program below will plot f[n,x] for k values of the parameter
n > for x in the interval [a,b], all on the same axis. Is there any
way > to place markers next to each plotted function so they can be
> distinguished from one another?  Color is out, this is for a grey
> scale NeXT station.

> Show[Table[Plot[f[n,x],{x,a,b}, DisplayFunction->Identity],
> {n,1,k}], DisplayFunction -> \$DisplayFunction]

Here are some ideas.

Using the program given, with
In[1]:=	f[n_,x_] := Sin[n x]
and numerical values for the parameters, we get.

In[2]:=	Show[Table[Plot[f[n,x],{x,0,2Pi}, DisplayFunction->Identity],
{n,1,4}],
DisplayFunction -> \$DisplayFunction
]//Timing

Out[2]= {1.45 Second, -Graphics-}

Fierstly, this can be simplified and speeded up by taking the table
inside Plot, which can plot a list of functions (note the use of
Evaluate inside Plot).

In[3]:= Plot[Evaluate[Table[f[n,x],{n,1,4}]],{x,0,2Pi}]//Timing

Out[3]=	{0.583333 Second, -Graphics-}

Now for distinguishing marks: I give three attempts. Many
variations are possible. Special cases are not dealt with eg. a
point lying on the x-axis or points not included in the plot range.

(1) put marks on the graphs; gray-out the graphs to show up the marks.

In[4]:=	Plot[Evaluate[Table[f[n,x],{n,1,4}]],{x,0,2Pi},
Epilog ->
Table[Text[n,{#,f[n,#]}&[Pi+Random[]]],{n,1,4}],
PlotStyle -> GrayLevel[.5]
]//Timing

Out[4]= {0.533333 Second, -Graphics-}

(2) put marks to the side with lines to the graphs.

In[5]:=	Plot[Evaluate[Table[f[n,x],{n,1,4}]],{x,0,2Pi},
Epilog ->
Table[
{Line[{{#,f[n,#]}, {2Pi+.1,f[n,#]}}],
Text[n,{2Pi+.1,f[n,#]},{-2,0}]
}&[Pi+Random[]],
{n,1,4}],
PlotStyle -> GrayLevel[.5],
PlotRange -> {{0, 2Pi + .5}, Automatic}
(*to get numbers on plot*)
]//Timing

Out[5]=	{0.616667 Second, -Graphics-}
(3) even with a grey scale system we can make some visual
distinction by using  PlotStyle to set thickness, dashing and
graylevel

In[6]:=	Plot[Evaluate[Table[f[n,x],{n,1,4}]],{x,0,2Pi},
Epilog :>
Table[
{ Line[{{#,f[n,#]}, {2Pi+.1,f[n,#]}}],
Text[n,{2Pi+.1,f[n,#]},{-2,0}]
}&[Pi+Random[]],
{n,1,4}
],
PlotRange -> {{0, 2Pi + .5}, Automatic},
(*to get numbers on plot*)
PlotStyle -> Table[GrayLevel[i/4],{i,0,3}]
]//Timing

Out[6]= {0.616667 Second, -Graphics-}

Finally; there is the package  Graphics`Legend`, and if you want
arrows instead of lines, the package Graphics`Arrows`.

Allan Hayes
hay at haystack.demon.co.uk

```

• Prev by Date: Re: Strange answer from Eigensystem[]!
• Next by Date: Re: Word - Mathematica connection