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

Image may be NSFW.
Clik here to view.

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

All of the previous answers are way over my head, at this state of my coding journey, so I just added another Matplotlib aspect called patches:import matplotlib.patches as mpatchesfirst_leg =...

View Article



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

To build on top of gboffi's andBen Usman's answer:In a situation where one has different lines in different subplots with the same color and label, one can do something along the lines...

View Article

Image may be NSFW.
Clik here to view.

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

TL;DRlines_labels = [ax.get_legend_handles_labels() for ax in fig.axes]lines, labels = [sum(lol, []) for lol in zip(*lines_labels)]fig.legend(lines, labels)I have noticed that none of the other answers...

View Article

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

If you are using subplots with bar charts, with a different colour for each bar, it may be faster to create the artefacts yourself using mpatches.Say you have four bars with different colours as r, m,...

View Article

Image may be NSFW.
Clik here to view.

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

Using Matplotlib 2.2.2, this can be achieved using the gridspec feature.In the example below, the aim is to have four subplots arranged in a 2x2 fashion with the legend shown at the bottom. A 'faux'...

View Article


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

This answer is a complement to user707650's answer on the legend position.My first try on user707650's solution failed due to overlaps of the legend and the subplot's title.In fact, the overlaps are...

View Article

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

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 =...

View Article

Answer by Saullo G. P. Castro for How do I make a single legend for many...

For the automatic positioning of a single legend in a figure with many axes, like those obtained with subplots(), the following solution works really well:plt.legend(lines, labels, loc = 'lower...

View Article


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

You just have to ask for the legend once, outside of your loop.For example, in this case I have 4 subplots, with the same lines, and a single legend.from matplotlib.pyplot import *ficheiros =...

View Article


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

figlegend may be what you're looking for: matplotlib.pyplot.figlegendAn example is at Figure legend demo.Another example:plt.figlegend(lines, labels, loc = 'lower center', ncol=5,...

View Article

How do I make a single legend for many subplots?

I am plotting the same type of information, but for different countries, with multiple subplots with Matplotlib. That is, I have nine plots on a 3x3 grid, all with the same for lines (of course,...

View Article
Browsing all 11 articles
Browse latest View live




Latest Images