Created
September 25, 2021 16:32
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From this question: https://stackoverflow.com/questions/9834452/how-do-i-make-a-single-legend-for-many-subplots-with-matplotlib