I can get a colored ListLinePlot
by doing something like
ListLinePlot[Range[420, 680, 20], ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False]
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]
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])
]
?
(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.
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.
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.
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.
ErrorListPlot [ { { { x1, y1 }, ErrorBar [ err1] }, { { x2, y2 }, ErrorBar [ err2] }, … }] plots points with specified x and y coordinates and error magnitudes.
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]
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]
You can use DiscretePlot
:
data = Range[420, 680, 20];
DiscretePlot[data[[i]], {i, Length[data]},
ColorFunction -> "VisibleSpectrum", ColorFunctionScaling -> False,
Filling -> None]
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]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With