Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Individual point coloring in ListPlot, ErrorListPlot in Mathematica

I can get a colored ListLinePlot by doing something like

ListLinePlot[Range[420, 680, 20], ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False]

Mathematica graphics

However, as indicated by the help file ("ColorFunction requires at least one dataset to be Joined"), if I do the equivalent

ListPlot[Range[420, 680, 20], ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False]

Mathematica graphics

all my points are blue. Is there a nice way to get ColorFunction to work for ListPlot with Joined -> False?

That is, is there a nicer way to get something like

ListPlot[
 List /@ Transpose[{Range[(680 - 420)/20 + 1], Range[420, 680, 20]}], 
 PlotMarkers -> ({Graphics[{#, Disk[]}], 0.05} & /@ ColorData["VisibleSpectrum"] /@ Range[420, 680, 20])
]

?

Mathematica graphics

(Also, does anyone have an explanation of why Mathematica requires Joined -> True in order to make use of ColorFunction?)

Edit: I'm also looking for a way to do a similar coloring with ErrorListPlot in the ErrorBarPlots package.

like image 851
Jason Gross Avatar asked Dec 31 '11 12:12

Jason Gross


People also ask

How do I use errorlistplot?

To use ErrorListPlot, you first need to load the ErrorBar Plotting Package using Needs [ "ErrorBarPlots`"]. Copy to clipboard. Plot data with associated errors: Copy to clipboard. Plot data with error bars: Copy to clipboard. Copy to clipboard.

How do I plot a list of data using listplot?

Plot the data using ListPlot: Use PlotMarkers to specify the point type and size for each dataset. The position of the point type and size specification in the list to the right of PlotMarkers corresponds to the dataset of the same position in the list that is the first argument to ListPlot.

How do I use plotmarkers in listplot?

Use PlotMarkers to specify the point type and size for each dataset. The position of the point type and size specification in the list to the right of PlotMarkers corresponds to the dataset of the same position in the list that is the first argument to ListPlot.

What is Error List plot in Python?

ErrorListPlot [ { { { x1, y1 }, ErrorBar [ err1] }, { { x2, y2 }, ErrorBar [ err2] }, … }] plots points with specified x and y coordinates and error magnitudes.


2 Answers

The problem is, that Joined->True draws a Line[] which can be given VertexColors for each containing point. I assume doing the same for the points when setting Joined->False leads to situations where it does not work. Nevertheless, Line[] and Point[] work pretty much the same in your case. So what is about

ListLinePlot[Range[420, 680, 20], ColorFunction -> "VisibleSpectrum", 
  ColorFunctionScaling -> False] /. Line[arg___] :> Point[arg]

Mathematica graphics

And, by the way, if your using a ListLinePlot only, where the only Line[] directives arising are the one from your data, this should work even if you have more datasets and {x,y} coordinates

data = Transpose[Table[{{x, Sin[x]}, {x, Cos[x]}}, {x, 0, 2 Pi, 0.2}]];
ListLinePlot[data, ColorFunction -> Hue] /. Line[arg___] :> Point[arg]

Mathematica graphics

like image 119
halirutan Avatar answered Oct 17 '22 19:10

halirutan


You can use DiscretePlot:

data = Range[420, 680, 20];
DiscretePlot[data[[i]], {i, Length[data]},
   ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False,
   Filling -> None]

Mathematica graphics

If you're plotting a list of x,y points, it gets a little trickier:

data = Transpose[{Range[420, 680, 20], Range[400, 530, 10]}];
mapping = Apply[Rule, data, 2];
DiscretePlot[i/.mapping, {i, data[[;;,1]]},
   ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False,
   Filling -> None]

Mathematica graphics

It does seem rather odd that DiscretePlot will let you color the points differently whereas ListPlot won't. I'm sure it must have something to do with the implementation details, but I can't think of a reason why that would be the case.

like image 3
David Z Avatar answered Oct 17 '22 18:10

David Z