All Questions
1,094
questions
1660
votes
18
answers
1.9m
views
How to put the legend outside the plot
I have a series of 20 plots (not subplots) to be made in a single figure. I want the legend to be outside of the box. At the same time, I do not want to change the axes, as the size of the figure gets ...
519
votes
9
answers
999k
views
How to change legend fontsize with matplotlib.pyplot
Simple question here: I'm trying to get the size of my legend using matplotlib.pyplot to be smaller (i.e., the text to be smaller). The code I'm using goes something like this:
plot.figure()
plot....
508
votes
7
answers
1.4m
views
Adding a matplotlib legend
How can one create a legend for a line graph in Matplotlib's PyPlot without creating any extra variables?
Please consider the graphing script below:
if __name__ == '__main__':
PyPlot.plot(length, ...
481
votes
11
answers
480k
views
Secondary axis with twinx(): how to add to legend
I have a plot with two y-axes, using twinx(). I also give labels to the lines, and want to show them with legend(), but I only succeed to get the labels of one axis in the legend:
import numpy as np
...
337
votes
10
answers
377k
views
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, ...
298
votes
7
answers
254k
views
Moving matplotlib legend outside of the axis makes it cutoff by the figure box
I'm familiar with the following questions:
Matplotlib savefig with a legend outside the plot
How to put the legend out of the plot
It seems that the answers in these questions have the luxury of ...
173
votes
5
answers
239k
views
How to manually create a legend
I am using matplotlib and I would like to manually add items to the legend that are a color and a label. I am adding data to to the plot to specifying there would lead to a lot of duplicates.
My ...
173
votes
4
answers
186k
views
Global legend and title aside subplots
I've started with matplot and managed some basic plots, but now I find it hard to discover how to do some stuff I need now :(
My actual question is how to place a global title and global legend on a ...
168
votes
4
answers
537k
views
matplotlib: colorbars and its text labels
I'd like to create a colorbar legend for a heatmap, such that the labels are in the center of each discrete color. Example borrowed from here:
import matplotlib.pyplot as plt
import numpy as np
from ...
119
votes
6
answers
94k
views
Stop matplotlib repeating labels in legend
Here is a very simplified example:
xvalues = [2,3,4,6]
for x in xvalues:
plt.axvline(x,color='b',label='xvalues')
plt.legend()
The legend will now show 'xvalues' as a blue line 4 times in the ...
118
votes
6
answers
126k
views
Show only certain items in legend
I currently am plotting a stacked bar graph of a large amount of taxonomic data, and only wish to show significant species in the legend (out of ~500 I wish to show ~25). Is there a simple way to do ...
116
votes
7
answers
129k
views
How is order of items in matplotlib legend determined?
I am having to reorder items in a legend, when I don't think I should have to. I try:
from pylab import *
clf()
ax=gca()
ht=ax.add_patch(Rectangle((1,1),1,1,color='r',label='Top',alpha=.1))
h1=ax.bar(...
113
votes
4
answers
340k
views
How to edit a seaborn legend title and labels for figure-level functions
I've created this plot using Seaborn and a pandas dataframe (data):
My code:
import seaborn as sns
g = sns.lmplot('credibility', 'percentWatched', data=data, hue='millennial', markers=["+",...
109
votes
4
answers
182k
views
How to place two different legends on the same graph
I have a plot where different colors are used for different parameters, and where different line styles are used for different algorithms. The goal is to compare the results of the different ...
108
votes
5
answers
371k
views
How to specify legend position in graph coordinates
I am aware of the bbox_to_anchor keyword and this thread, which very helpfully suggests how to manually place the legend:
How to put the legend out of the plot
However, I'd like to use the ...