10

The code

using Plots
pyplot(markershape = :auto)
for i in 1:4
  plot!(rand(10), label = "Series " * string(i))
end
savefig("Plot.png")

produces the following plot:

enter image description here

The markers do not appear in the legend, only the data series's line color. This makes it significantly harder to match the lines up with the labels in the legend, especially for those who are colorblind or reading off of a black-and-white printout. Is there a way to display the plot markers as well as line colors in the legend?

tparker
  • 689
  • 1
  • 6
  • 17

2 Answers2

7

I am adding an answer for posterity - this has been fixed in Plots, so this works:

plot(rand(10,4), markershape = :auto)

enter image description here

Michael K. Borregaard
  • 7,864
  • 1
  • 28
  • 35
3

There's probably a more efficient, straightforward way but you can try plotting the line / markers separately:

using Plots
pyplot(markershape = :auto)
for i in 1:4
    x = rand(10)
    plot!(x, color=i, marker=false, label="")
    scatter!(x, color=i, markersize=10, label = "Series " * string(i))
end
savefig("Plot.png")

plot

label="" suppresses the legend entry for the line

color=i ensures that the color of the lines/markers are the same

Alain
  • 853
  • 11
  • 10
  • That's an improvement, but ideally I'd like to display both the marker and the line in the legend, to most accurately reflect the actual plot. – tparker Jun 07 '17 at 18:46
  • Another issue with this solution: the line plot still increments the marker type, so this solution cycles through every *second* plot marker, resulting in a different order of markers as in a scatter-only plot. Any idea how to get around this? – tparker Jun 07 '17 at 20:59
  • 2
    You've unfortunately got to use some hack like this at the moment to get this to work. It'd be nice with a seriestype that had both line and marker, but at the moment there isn't one. You could open an issue on Plots :-) – Michael K. Borregaard Jun 07 '17 at 22:21
  • It works now - I've added another answer for posterity to find. – Michael K. Borregaard Oct 05 '17 at 11:00