Quantcast
Channel: How do I make a single legend for many subplots? - Stack Overflow
Viewing all articles
Browse latest Browse all 11

Answer by Ben Usman for How do I make a single legend for many subplots?

$
0
0

There is also a nice function get_legend_handles_labels() you can call on the last axis (if you iterate over them) that would collect everything you need from label= arguments:

handles, labels = ax.get_legend_handles_labels()fig.legend(handles, labels, loc='upper center')

If the pyplot interface is being used instead of the Axes interface, use:

handles, labels = plt.gca().get_legend_handles_labels()

To remove legends from subplots, see Remove the legend on a matplotlib figure.

To merge txinx legends, see Secondary axis with twinx(): how to add to legend.


Viewing all articles
Browse latest Browse all 11

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>