Skip to main content

Questions tagged [legend]

A graph legend is commonly used when plotting several sets of data within the same diagram. The legend associates each plot with its corresponding data.

legend
1657 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
517 votes
9 answers
996k 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
507 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
479 votes
11 answers
478k 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
  • 137k
375 votes
4 answers
599k views

Remove legend ggplot 2.2

I'm trying to keep the legend of one layer (smooth) and remove the legend of the other (point). I have tried shutting off the legends with guides(colour = FALSE) and geom_point(aes(color = vs), show....
Guy's user avatar
  • 3,775
337 votes
10 answers
376k 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
328 votes
11 answers
441k views

Remove the legend on a matplotlib figure

To add a legend to a matplotlib plot, one simply runs legend(). How to remove a legend from a plot? (The closest I came to this is to run legend([]) in order to empty the legend from data. But that ...
Olivier Verdier's user avatar
297 votes
7 answers
253k 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,321
222 votes
11 answers
451k views

Plot a legend outside of the plotting area in base graphics?

As the title says: How can I plot a legend outside the plotting area when using base graphics? I thought about fiddling around with layout and produce an empty plot to only contain the legend, but I ...
Henrik's user avatar
  • 14.4k
212 votes
9 answers
270k views

Add a common Legend for combined ggplots

I have two ggplots which I align horizontally with grid.arrange. I have looked through a lot of forum posts, but everything I try seem to be commands that are now updated and named something else. ...
jO.'s user avatar
  • 3,472
200 votes
8 answers
73k views

Remove 'a' from legend when using aesthetics and geom_text

How can I can remove the letter 'a' from the legend generated by this code? If I remove the geom_text, then the 'a' letter will not show in the legend. I want to keep geom_text, though. ggplot(data = ...
user2700207's user avatar
  • 2,043
187 votes
9 answers
193k views

Is there a way to change the spacing between legend items in ggplot2?

Is there a way to change the spacing between legend items in ggplot2? I currently have legend.position ="top" which automatically produces a horizontal legend. However, the spacing of the items is ...
overflowname's user avatar
  • 2,153
184 votes
4 answers
405k views

Add legend to ggplot2 line plot

I have a question about legends in ggplot2. I managed to plot three lines in the same graph and want to add a legend with the three colors used. This is the code used library(ggplot2) ## edit from ...
pacomet's user avatar
  • 5,111
173 votes
5 answers
237k 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

15 30 50 per page
1
2 3 4 5
345