Set point color in ListPlot when multiple datasets are built

Version 8.04 for Windows.

I noticed that when I have 2 data sets and use ListPlot for them, the points shown do not match the color specified by the PlotStyle parameter for the line color itself when using Joined->True .

I just want to find out if I can not understand the meaning of PlotStyle here.

Here is an example:

 data1 = {{1, 1}, {2, 1.5}, {3, 2}}; data2 = {{1, 1.5}, {2, 2.5}, {3, 3}}; ListPlot[{data1, data2}, PlotStyle -> {Red, Blue}, Joined -> False, Mesh -> All, AxesOrigin -> {0, 0}] 

enter image description here

Note that the dots have the correct colors according to PlotStyle (red, then blue).

Now, when I add Joined->True , let's see what happens:

 data1 = {{1, 1}, {2, 1.5}, {3, 2}}; data2 = {{1, 1.5}, {2, 2.5}, {3, 3}}; ListPlot[{data1, data2}, PlotStyle -> {Red, Blue}, Joined -> True, Mesh -> All, AxesOrigin -> {0, 0}] 

enter image description here

Now the dots in the top line, which are blue, have changed color to red, which is the color of the dots of the bottom line !.

It makes sense?

One way to overcome this is to explicitly add PlotMarkers to give colors to the dots, for example:

 data1 = {{1, 1}, {2, 1.5}, {3, 2}}; data2 = {{1, 1.5}, {2, 2.5}, {3, 3}}; ListPlot[{data1, data2}, PlotStyle -> {Red, Blue}, Joined -> True, Mesh -> All, AxesOrigin -> {0, 0}, PlotMarkers -> {{Graphics[{Red, Point[{0, 0}]}], 12}, {Graphics[{Blue, Point[{0, 0}]}], 12}}] 

enter image description here

Question: Why do the dots change color to red in the top row (second graph above)? and is there a simpler solution for this that I did above?

edit (1)

try MeshStyle -> {Red, Blue} also mixes things:

 data1 = {{1, 1}, {2, 1.5}, {3, 2}}; data2 = {{1, 1.5}, {2, 2.5}, {3, 3}}; ListPlot[{data1, data2}, PlotStyle -> {Red, Blue}, Joined -> True, AxesOrigin -> {0, 0}, Mesh -> All, MeshStyle -> {Red, Blue}] 

enter image description here

thanks

+4
source share
2 answers

I think it is Mesh->All that messed things up. You can specify MeshStyle or just leave it turned off and set PlotMarkers->Automatic .

 ListPlot[{data1,data2},PlotStyle->{Red,Blue},Joined->True, PlotMarkers->Automatic,AxesOrigin->{0,0}] 

Mathematica graphics

+4
source

To get just colored dots without changing their shape or repeating the colors of the lines in the code, you can use PlotMarkers , as here:

 ListPlot[{data1, data2}, PlotStyle -> {Red, Blue}, Joined -> True, PlotMarkers -> Graphics@ {Point[{0, 0}]}, AxesOrigin -> {0, 0}] 

output of the above command

0
source

Source: https://habr.com/ru/post/1391061/


All Articles