Learning Plots... now: marker_z?


#1

I’m trying to learn Plots, and now: the marker_z keyword.

With

xm=randn(100);
ym=randn(100);

the following two commands (pyplot backend) give almost the same plots:

scatter(xm,ym)
plot(xm,ym, markershape=:circle,linecolor=false)

HOWEVER:

scatter(xm,ym,marker_z=1:100)

works, while:

plot(xm,ym, markershape=:circle,linecolor=false,marker_z=1:100)

fails miserably.

Why?


#2

I should add…

plot(xm,ym, markershape=:circle,linecolor=false,marker_z=1:100)

does in fact work if I use the gr backend… [not quite, though: the legend is wrong: black, filled marker, and the line is included in the marker… maybe I should set the linecolor differently?]


#3

It is weird that GR and PyPlot give different answers here…

That said, I am not precisely sure of what you expected to happen. If you just use

plot(xm,ym,seriestype=:scatter,markershape=:circle,linecolor=false,marker_z=1:100)

then you will find that the code will work the same on both backends. The difference here is that I added seriestype=:scatter. So the moral of the story is that scatter and plot do different things.

From the documentation:

line_z and marker_z parameters will map data values into a ColorGradient value

I hope that this helps.

PS: Have a look at this post on backticks


It allows you to get your code looking beautiful on discourse. It might help if you try asking a more complex question.


#4

Thanks for quick answer and tip on backtics!

OK – so seriestype=:scatter fixes this, and reduces the need to set linecolor=false. Apart from this, I would have guessed that scatter was just a shorthand for plot with defined markershape and linecolor set to false. So there must be more to scatter…?


#5

scatter(...) is short for plot(..., seriestype = :scatter). You should set the seriestype rather than mess around with markershape etc.
Also, linecolor is an alias for seriescolor, i.e. it will also affect the color of markers. Don’t use linecolor = false to hide the line.


#6

Thanks for clarification: I guess that my “problem” of wanting to set both linestyle and marker (in the default seriestype, stems from by MATLAB background…).

Is linecolor really an alias for seriescolor? To me, the documentation seems to indicate that linecolor by default inherits from seriescolor, but may be set to be different:

image

Btw: this inserted screen capture is from Firefox (it is similar in MS Edge), and illustrates a problem with the documentation… the Description cell for linestyle doesn’t show fully, and it is not possible to scroll sideways. The only way to see what follows after :dashd.. is to attempt to copy the cell content and paste it into an editor.


#7

Thanks for reporting @BLI ! This should be fixed for pyplot in https://github.com/JuliaPlots/Plots.jl/pull/1460.