Learning Plots... now: marker_z?

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



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

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



works, while:

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

fails miserably.


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?]

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


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.

1 Like

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…?

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.

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:


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.

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