Skip to content

Instantly share code, notes, and snippets.

@AayushSameerShah
Created September 25, 2021 16:32
Show Gist options
  • Save AayushSameerShah/c15efa874b085022e8c9643593ec573d to your computer and use it in GitHub Desktop.
Save AayushSameerShah/c15efa874b085022e8c9643593ec573d to your computer and use it in GitHub Desktop.
This is how to put the single - common legend when you have made a single plot with multiple axes.
handles_0, labels_0 = axes[0].get_legend_handles_labels()
handles_1, labels_1 = axes[1].get_legend_handles_labels()
handels = handles_0 + handles_1
labels = labels_0 + labels_1
fig.legend(handels, labels, loc=(0.83, 0.85))
"""Here, the main function is `.get_legend_handles_labels()`
it will return the labels and handles for individual plots
Then we have to make a GLOBAL list that covers all handles and labels
and then finally put them in the legend call"""
@AayushSameerShah
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment