MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ListPlot command

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9758] Re: [mg9710] ListPlot command
  • From: Luci Ellis <elisha at dot.net.au>
  • Date: Tue, 25 Nov 1997 00:07:03 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Ezra.

The solution to your problem is not difficult: you just have to create
three graphs with the DisplayFunction-> Identity option, so they don't
show, each with  different values for the PlotStyle->something option
and then use the Show[..., DisplayFunction ->$DisplayFunction] command
to show them all as one graph.  You could even set it up as a little
function (try pasting this into your Mathematica notebook):

multiplot[data:{{_Real,_Real}..}..,opts___?OptionQ]:=
	Show[ListPlot[#,PlotJoined->True,
          PlotStyle->
            Hue[Flatten[(Position[{data},#])/Length[{data}]][[1]] ],
          DisplayFunction->Identity] & /@ {data},opts,
    	DisplayFunction->$DisplayFunction]

Of course, this picks out colors for your lines that are evenly spaced
along the Hue[] spectrum and this may not look attractive! So you could
add another argument that is a list of graphics options like this:

multiplot[data:{{_Real,_Real}..}..,colors_List,opts___?OptionQ]:=
    Show[ListPlot[#,PlotJoined->True,
            PlotStyle->Flatten[colors[[ Flatten[Position[{data},#]] ]]
],
            DisplayFunction->Identity] & /@ {data},opts,
      DisplayFunction->$DisplayFunction]

testdata1 = Table[{Random[],Random[]},{10}]; testdata2 =
Table[{Random[],Random[]},{10}]; multiplot[testdata1, testdata2,
	{Hue[0.65],{GrayLevel[0.7],AbsoluteThickness[2]}},Frame->True]

Note that if you supplied a list of graphics directives with fewer
elements than the number of datasets you supplied, you would get an
error. I tried to trap this with an
If[Length[{data}]<=Length[colors],... ,Message[...]] but it didn't
work.

The other method (which I am sure others will mention) is to use the
Graphics`MultipleListPlot` Package that comes standard with version 3
(and probably version 2). I just use the first method though: it works
fine for me.

Hope this helps,
Luci

>Hi.
>I have three lists of (x,y) pairs which I would like to plot on the same
>graph.
>I would like each list to be assigned a different color, and can not
>figure out how to do this.  Does anyone have any ideas?


--------------
Luci Ellis:  elisha at dot.net.au
http://www.dot.net.au/~elisha



  • Prev by Date: Re: ListPlot command
  • Next by Date: ListPlot Command (Addendum)
  • Previous by thread: Re: ListPlot command
  • Next by thread: RE: ListPlot command