MathGroup Archive 2007

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

Search the Archive

Re: conditional plotstyles in ListPlot


Stern wrote:
> I am plotting a time series and would like to use different colors for
> points above the x-axis from the colors below the x-axis. I can think
> of some relatively inelegant ways of doing this, splitting my dataset
> in two, plotting them separately, and them showing the graphs
> together, but I feel as though there may be a better solution.

Hi Michael,

Splitting your graph in two is not required. In the following example,
we use a pure function to build a sequence of pairs {color, point}.

In[1]:=
data = Sort[Table[Random[Integer, {-5, 5}], {10}, {2}]];
ListPlot[data, PlotJoined -> True,
    Epilog -> {AbsolutePointSize[4],
      ({If[#1[[2]] > 0, Red, Green], Point[#1]} & ) /@ data}];

Hope this helps,
Jean-Marc


  • Prev by Date: Re: conditional plotstyles in ListPlot
  • Next by Date: Re: Curve-fitting/data analysis question...
  • Previous by thread: Re: conditional plotstyles in ListPlot
  • Next by thread: Re: conditional plotstyles in ListPlot