Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legend entries don't correspond to the desired plots #102

Closed
kunalmenda opened this issue Aug 25, 2018 · 4 comments
Closed

Legend entries don't correspond to the desired plots #102

kunalmenda opened this issue Aug 25, 2018 · 4 comments

Comments

@kunalmenda
Copy link

Say I plot as follows:

ax = Axis()
push!(ax, Plots.Linear(x0,y0))
push!(ax, Plots.Linear(x1,y1), legendentry="leg1")
push!(ax, Plots.Linear(x2,y2), legendentry="leg2")

The resulting legend will have "leg1" and "leg2" correspond to the first and second lines respectively as opposed to the desired second and third lines. The suggested work around is:

ax = Axis()
push!(ax, Plots.Linear(x0,y0), style="forget plot")
push!(ax, Plots.Linear(x1,y1), legendentry="leg1")
push!(ax, Plots.Linear(x2,y2), legendentry="leg2")

Would it be possible to make "forget plot" a default option?

@tawheeler
Copy link
Member

Want to make a branch, make the change, and see whether the behavior has any undesired consequences?

@mykelk
Copy link
Member

mykelk commented Aug 27, 2018

I think forget plot might not be what we want. I'll take this one on, after it is working in Julia 1.0, which should be by tomorrow.

@mykelk mykelk self-assigned this Aug 27, 2018
@mykelk mykelk removed their assignment Aug 16, 2020
@mykelk
Copy link
Member

mykelk commented Aug 16, 2020

Yeah, forget plot is not what we want. It will leave the plot out of the legend (which is good), but it won't advance the cycle list. I think we probably need to go about handling legends differently, perhaps with the \legend command, which allows us to add empty legends as mentioned here. Right now, the implementation uses the \addlegendentry command.

@mossr
Copy link
Member

mossr commented Aug 16, 2020

I submitted a PR #153 based on code Mykel passed along to me and got \legend{} working nicely. We can now handle the MWE that Kunal posted (and all examples in the Jupyter notebook passed):

using PGFPlots
x0,y0 = rand(10), rand(10)
x1,y1 = 1:10, 1:10
x2,y2 = 10:-1:1, 1:10
ax = Axis()
push!(ax, Plots.Linear(x0,y0))
push!(ax, Plots.Linear(x1,y1,legendentry="leg1"))
push!(ax, Plots.Linear(x2,y2,legendentry="leg2"))
ax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants