Skip to main content

All Questions

Tagged with
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 ...
pottigopi's user avatar
  • 16.6k
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....
mike's user avatar
  • 23.5k
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, ...
Nafiul Islam's user avatar
  • 81.8k
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 ...
joris's user avatar
  • 138k
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, ...
pocketfullofcheese's user avatar
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 ...
jonathanbsyd's user avatar
  • 8,341
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 ...
Brady forcier's user avatar
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 ...
Gere's user avatar
  • 12.5k
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 ...
dimka's user avatar
  • 4,459
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 ...
Anake's user avatar
  • 7,549
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 ...
Funsaized's user avatar
  • 2,056
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(...
CPBL's user avatar
  • 3,940
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=["+",...
Oliver G's user avatar
  • 1,161
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 ...
Charles Brunet's user avatar
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 ...
mzzx's user avatar
  • 2,104

15 30 50 per page
1
2 3 4 5
73