I have a list of 2D points I want to plot with ListPlot
. I want the edges connecting these points to have certain colors. So in addition to setting the ListPlot
option Joined
to True
, I will also need to set the Mesh
and MeshShading
options. As far as I know, the only value for the Mesh
option that will put a mesh point at each point I pass to ListPlot
is Mesh->Full
. However, if I use this value, then the MeshShading
option doesn't seem to do anything.
To get a minimum working example, I will just go to the ListPlot
documentation and go to Options and then MeshShading in their drill-down menu.
The first example is
ListPlot[Table[Binomial[15, k], {k, 0, 15}], Mesh -> 10,
MeshShading -> {Red, Blue}, Joined -> True]
which produces
But, as I explained, I will have to use Mesh->Full
, so I make this change to the command to get the following command
ListPlot[Table[Binomial[15, k], {k, 0, 15}], Mesh -> Full,
MeshShading -> {Red, Blue}, Joined -> True]
The command produces the following plot:
As you can see, the mesh does not have the specified coloring. My question is, "How do I get ListPlot
to use the given value of the MeshShading
option when I am also using the option Mesh->Full
?"
Notice that I realize
ListPlot[Table[Binomial[15, k], {k, 0, 15}], Mesh -> {Range[16], {}},
MeshShading -> {Red, Blue}, Joined -> True]
(for example), gives me what I want in this case, but in general, I will be plotting an arbitrary list of 2D points, so this will not work.
Mesh -> Length[points]
, wherepoints
is your arbitrary list of 2D points, work? More explicitly, once the listpoints
is generated, something like:With[{p = points}, ListPlot[p, Mesh -> Length[p], MeshShading -> {Red, Blue}, Joined -> True]]
. $\endgroup$Length[points]
evenly spaced values. Try it.ListPlot[RandomReal[{-1, 1}, {12, 2}], Mesh -> 12, MeshShading -> {Red, Blue}, Joined -> True]
$\endgroup$Show
,Graphics
(to draw colored lines) andListPlot
(for the points), but this seems a little ugly (and as a workaround, it does not answer your question). $\endgroup$Mesh
? $\endgroup$data = RandomReal[{-1, 1}, {12, 2}]; ListPlot[data, Mesh -> {data[[;; , 1]], {}}, MeshShading -> {Red, Blue}, Joined -> True]
$\endgroup$