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 doesn't work with line+symbol plots #198

Open
mauro3 opened this issue Jan 29, 2015 · 2 comments
Open

legend doesn't work with line+symbol plots #198

mauro3 opened this issue Jan 29, 2015 · 2 comments

Comments

@mauro3
Copy link

mauro3 commented Jan 29, 2015

This adds both legends to the black-plot. One to the line, one to the "o". (this is on commit 705449e)

using Winston
plot([1,2], "o-")
oplot([1,3], "o-r")
legend(["black", "red"])
@heliosdrm
Copy link
Collaborator

That's an issue related to the structure of the plots in Winston.
plot(x,y,"o-"), etc. actually creates two plot components, one for the line and another for the points; and each one has a different key in the legends.

There is no plot component type (that I am aware of) that may be used to put both components into a single one, and create a mixed legend. It might be created, but it does not exist in this moment.

A workaround is creating two overlapping legends manually:

using Winston
p = plot([1,2], "o-")
oplot([1,3], "o-r")
comp = getcomponents(p)
[setattr(comp[i], label="black") for i=1:2]
[setattr(comp[i], label="red") for i=3:4]
leg1 = Legend(0.1,0.9,{comp[1], comp[3]})
leg2 = Legend(0.1,0.9,{comp[2], comp[4]})
add(p, leg1, leg2)

@heliosdrm
Copy link
Collaborator

The creation of combined legends can be done more easily with the type "PlotGroup" that I have added in this fork: https://github.com/heliosdrm/Winston.jl/tree/legend (proposed as pull request #200).

Example:

using Winston
# Assign the plot to variable p to get the list of components
p = plot([1,2], "o-")
oplot([1,3], "o-r")
comp = getcomponents(p)

# use Winston.PlotGroup(components::Array{Any,1}) to group the plot components:
# comp[1:2] contain the black line and points, comp[3:4] the red ones.
# Add these two groups to a new plot p2, and make the legend for them.
p2 = FramedPlot()
add(p2, Winston.PlotGroup(comp[1:2]), Winston.PlotGroup(comp[3:4]))
legend(p2, ["black", "red"])

combinedlegend

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

2 participants