question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Legend with Multiple plots

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kpondercommented, 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.

0reactions
drphilmarshallcommented, Nov 13, 2015

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 https://github.com/dfm/corner.py/issues/63#issuecomment-156478435.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Legend for multiple plots - MATLAB Answers - MathWorks
I want to generate a legend for multiple plots on the same figure using 'hold on;'. I am using a certain method I...
Read more >
Common legend for multiple plots in R - Stack Overflow
Each graph has the same legend information, so rather than having a legend in each plot I would like to have one horizontal...
Read more >
Customizing Plot Legends | Python Data Science Handbook
The plt.plot() command is able to create multiple lines at once, and returns a list of created line instances. Passing any of these...
Read more >
How to Create a Single Legend for All Subplots in Matplotlib?
Sometimes it is necessary to create a single legend for all subplots. Below are the examples that show a single legend for all...
Read more >
Legend Demo — Matplotlib 3.6.2 documentation
Plotting legends in Matplotlib. There are many ways to create and customize legends in Matplotlib. Below we'll show a few examples for how...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found