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 with Multiple plots #63

Closed
kponder opened this issue Oct 22, 2015 · 5 comments
Closed

Legend with Multiple plots #63

kponder opened this issue Oct 22, 2015 · 5 comments

Comments

@kponder
Copy link

kponder commented Oct 22, 2015

Hello,

I have two corner plots that I overlay using the fig=fig keyword. It is only with two parameters and I wanted to add a legend in the empty corner. One plots the contours blue and the other one plots red. Is there a simple way to do this with corner.py?

Thank you,
Kara

@kbarbary
Copy link
Contributor

I don't know of a simple way.

You should be able to use fig.legend as in this example: http://matplotlib.org/examples/pylab_examples/figlegend_demo.html

However, you need a handle to the lines in the plot for that. If you can't pull these out of the figure object, you could use a proxy artist.

@kponder
Copy link
Author

kponder commented Oct 23, 2015

Thanks for the suggestion, Kyle.

I was able to do it with

import matplotlib.lines as mlines

blue_line = mlines.Line2D([], [], color='blue', label='SGM')
red_line = mlines.Line2D([], [], color='red', label='GMM')
fig = corner(samples, color = 'b')
corner(samples1, color = 'r', fig=fig)

plt.legend(handles=[blue_line,red_line], bbox_to_anchor=(0., 1.0, 1., .0), loc=4)

This does attach the legend to the last plot in the figure (the bottom right histogram) so I moved it out of the plot and into the empty space.

@kponder kponder closed this as completed Oct 23, 2015
@drphilmarshall
Copy link

Nice! Can you paste in the resulting plot so we can take a look at your
handiwork, please? Thanks!

On Fri, Oct 23, 2015 at 1:32 PM, Kara Ponder notifications@github.com
wrote:

Thanks for the suggestion, Kyle.

I was able to do it with

import matplotlib.lines as mlines

blue_line = mlines.Line2D([], [], color='blue', label='SGM')
red_line = mlines.Line2D([], [], color='red', label='GMM')
fig = corner(samples, color = 'b')
corner(samples1, color = 'r', fig=fig)

plt.legend(handles=[blue_line,red_line], bbox_to_anchor=(0., 1.0, 1., .0), loc=4)

This does attach the legend to the last plot in the figure (the bottom
right histogram) so I moved it out of the plot and into the empty space.


Reply to this email directly or view it on GitHub
#63 (comment).

@kponder
Copy link
Author

kponder commented Nov 13, 2015

Sure thing!

20151024_0_smo_10_dM_1000_num_2_OmW.pdf

(Look for it on the arXiv next week.)

@drphilmarshall
Copy link

Alright! Very nice :-) The only design choices I might suggest would be to
center the legend in the blank panel (both horizontally and vertically) and
remove the box around it. I guess at least sometimes one would also want to
legend the truth point as well.

On Friday, November 13, 2015, Kara Ponder notifications@github.com wrote:

Sure thing!

20151024_0_smo_10_dM_1000_num_2_OmW.pdf
https://github.com/dfm/corner.py/files/34136/20151024_0_smo_10_dM_1000_num_2_OmW.pdf

(Look for it on the arXiv next week.)


Reply to this email directly or view it on GitHub
#63 (comment).

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

3 participants