Plots.jl: Multiple legend labels with `pyplot()` are misformatted. Works fine under `gr()`

Created on 9 Sep 2019  路  3Comments  路  Source: JuliaPlots/Plots.jl

gr(); plot(rand(10,5),label=[1,2,3,4,5]) results in:

image

but with pyplot(); plot(rand(10,5),label=[1,2,3,4,5]) results in this presumably incorrect behavior:

image

PyPlot v"2.8.2"
Plots v"0.26.2"
PyPlot.PyCall.pyimport("matplotlib").__version__ == "3.1.1"
Julia version v"1.4.0-DEV.106"

Most helpful comment

At first the pyplot behaviour seems incorrect, although in some ways it is more correct.

Each line on your plot is a column of your random array and the labels are the corresponding "columns" of the thing that your passed to the label argument. When you pass a 5x1 array, there are not enough columns, so pyplot repeats the one column that you give it. On the other hand if you did label=[1 2 3 4 5] (a 1x5 array), then you have 5 columns of length one, so you get what you expect.

In any case, the backends should display the same thing, so we need to decide which one is "more wrong" and fix that one.

All 3 comments

At first the pyplot behaviour seems incorrect, although in some ways it is more correct.

Each line on your plot is a column of your random array and the labels are the corresponding "columns" of the thing that your passed to the label argument. When you pass a 5x1 array, there are not enough columns, so pyplot repeats the one column that you give it. On the other hand if you did label=[1 2 3 4 5] (a 1x5 array), then you have 5 columns of length one, so you get what you expect.

In any case, the backends should display the same thing, so we need to decide which one is "more wrong" and fix that one.

IMO pyplot has the correct behaviour.

Agreed. I am happy to fix this, although I wont have time for a little over 24 hours, so it is quite possible that someone will beat me to it.

I think that whoever does fix this should also have a look at the docs to check if this is discussed. If not, then maybe there is scope for some clarification.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Cody-G picture Cody-G  路  3Comments

kleinschmidt picture kleinschmidt  路  3Comments

apalugniok picture apalugniok  路  3Comments

dancsi picture dancsi  路  4Comments

daschw picture daschw  路  3Comments