MathGroup Archive 2009

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

Search the Archive

Re: ListPlot ColorFunction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99149] Re: ListPlot ColorFunction
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
  • Date: Tue, 28 Apr 2009 04:48:12 -0400 (EDT)
  • References: <gt3tma$npk$1@smc.vnet.net>

Hidden in the Options section of the ListPlot documentation page
you'll find

"ColorFunction requires at least one dataset to be Joined"

Nevertheless, you can achieve what you want in a somewhat clumsy way
by having ListPlot plot nine one-point plots and specifying the color
for each in PlotStyle and FillingStyle (the PointSize directive goes
to BaseStyle):

data = {9, 4, 1, 0, 0, 0, 1, 4, 9};
ListPlot[
 {#} & /@ Transpose[{Range[Length[data]], data}],
 Filling -> Axis,
 PlotStyle -> ((If[# == 0, RGBColor[1, 0, 0], RGBColor[0, 0, 1]] &) /@
     data),
FillingStyle -> ((If[# == 0, RGBColor[1, 0, 0],
       RGBColor[0, 0, 1]] &) /@ data),
 BaseStyle -> PointSize -> 0.02
 ]

Cheers -- Sjoerd

On Apr 27, 11:25 am, "Serych Jakub" <Ser... at panska.cz> wrote:
> Dear Mathematica users,
> first let me thank you for many nice zigzag solutions from my previous post.
>
> Today I have another question. I need to highlight some data points in
> ListPlot by changing their color. How to do it? I tried the similar solution
> which somebody have sent me time ago for the same problem which I had with
> Plot, but it doesn't work with ListPlot.
>
> In the example below I'm trying to make the zero points Red and all other
> Blue.
>
> ListPlot[{9, 4, 1, 0, 0, 0, 1, 4, 9}, Filling -> Axis,
>  PlotStyle -> PointSize[0.02],
>  ColorFunction -> (If[# == 0, RGBColor[1, 0, 0], RGBColor[0, 0, 1]] &)]
>
> Thanks in advance for any help
>
> Jakub



  • Prev by Date: Re: combine tabled graphics
  • Next by Date: Re: Bug in Mathematica 7.0?
  • Previous by thread: Re: ListPlot ColorFunction
  • Next by thread: combine tabled graphics