MathGroup Archive 1997

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

Search the Archive

Re: Colored ListPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9041] Re: Colored ListPlot
  • From: tburton at cts.com (Tom Burton)
  • Date: Thu, 9 Oct 1997 01:42:20 -0400
  • Organization: Brahea Consulting
  • Sender: owner-wri-mathgroup at wolfram.com

On 7 Oct 1997 03:14:01 -0400, in comp.soft-sys.math.mathematica you
wrote:

If it is possible I would like to ListPlot["list"], where list of points
in the plane, but with the following quality. 
The points will be joined (easily done with PlotJoined-> True), and they
should have a color function assigned to them so that the color of each
joining line is determined in some way by the points on the ends.

------------

First, you can do this easily (perhaps not so easily at first) without
ListPlot:

In[10]:= data = Table[{i,Sin[i]},{i,0,10,.1}];

In[11]:= Show[Graphics[
    Partition[data,2,1]
    /.{p1_,p2_}:>{Hue[0.25(2+Last[p1+p2])],Line[{p1,p2}]},
    Axes->True]]

Explanations of In[11]:

Line [11]/2:  Partition the data into overlapping pairs of points
{{p1,p2},{p2,p3},...}, where p1=={x1,y1}, etc.

Line [11]/3:  Rewrite each pair {p1,p2} as
{Hue[0.25(2+Last[p1+p2])],Line[{p1,p2}]}. This keys the color of each
line segment to the midpoint y-value of the segment. The Hue function
expects a real argument in the range [0,1] and will Mod its argument
back onto this domain if needed.

Line [11]/4: Turn on axes and axis labels.

If ListPlot does something for you that Graphics does not, then You can
also superimpose this plot on a ListPlot using Show as explained in the
Mathematica Book.

Hope this helps.
Tom Burton


  • Prev by Date: RE: Re: Useful Dumb User Questi
  • Next by Date: Re: Mysterious error message
  • Previous by thread: Re: Colored ListPlot
  • Next by thread: Re: Colored ListPlot