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.

A legend attached to a graph (or other visualization of data) is used to explain the graphical language (colors, symbols, lines, etc) of the specific visualization.

In scientific software for statistical computing and graphics and also , function legend adds a legend box to an existing plot.

4990 questions
84
votes
4 answers

increase the linewidth of the legend lines in matplotlib

I know that if I change the linewidth of a line, that is automatically updated in the legend. However I would like to just change the legend linewidth without affecting the plot.
Andrea Zonca
  • 8,378
  • 9
  • 42
  • 70
80
votes
5 answers

Setting a fixed size for points in legend

I'm making some scatter plots and I want to set the size of the points in the legend to a fixed, equal value. Right now I have this: import matplotlib.pyplot as plt import numpy as np def rand_data(): return np.random.uniform(low=0., high=1.,…
Gabriel
  • 40,504
  • 73
  • 230
  • 404
80
votes
8 answers

Set legend symbol opacity

I'm working on a plot with translucent 'x' markers (20% alpha). How do I make the marker appear at 100% opacity in the legend? import matplotlib.pyplot as plt plt.plot_date( x = xaxis, y = yaxis, marker = 'x', color=[1, 0, 0, .2], label='Data…
Don Albrecht
  • 1,222
  • 1
  • 8
  • 12
77
votes
1 answer

Control ggplot2 legend look without affecting the plot

I'm plotting lines with ggplot2 like this: ggplot(iris, aes(Petal.Width,Petal.Length,color=Species)) + geom_line() + theme_bw() . I find legend marks to be small so I want them to be bigger. If I change the size, lines on the plot change…
baltazar
  • 1,659
  • 2
  • 18
  • 23
75
votes
9 answers

How to set font size of Matplotlib axis Legend?

I have a code like this: import matplotlib.pyplot as plt from matplotlib.pyplot import * from matplotlib.font_manager import FontProperties fontP = FontProperties() fontP.set_size('xx-small') fig=plt.figure() ax1=fig.add_subplot(111) plot([1,2,3],…
Tapajit Dey
  • 1,327
  • 2
  • 13
  • 22
75
votes
9 answers

How do I assign multiple labels at once in matplotlib?

I have the following dataset: x = [0, 1, 2, 3, 4] y = [ [0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [9, 8, 7, 6, 5] ] Now I plot it with: import matplotlib.pyplot as plt plt.plot(x, y) However, I want to label the 3 y-datasets with this command,…
Kit
  • 30,365
  • 39
  • 105
  • 149
70
votes
4 answers

Change main plot legend label text

So far I have been able to label the subplots just fine but I'm having an issue with the main one. Here's the relevant part of my code: data_BS_P = data[channels[0]] data_BS_R = data[channels[1]] data_BS_Y = data[channels[2]] plot_BS_P =…
N.K.
  • 733
  • 1
  • 5
  • 9
66
votes
4 answers

Remove line through marker in matplotlib legend

I have a matplotlib plot generated with the following code: import matplotlib.pyplot as pyplot Fig, ax = pyplot.subplots() for i, (mark, color) in enumerate(zip( ['s', 'o', 'D', 'v'], ['r', 'g', 'b', 'purple'])): ax.plot(i+1, i+1,…
jlconlin
  • 14,206
  • 22
  • 72
  • 105
65
votes
2 answers

plot legends without border and with white background

I have a legend in a plot with a line (from an abline-statement) going through it. How can I achieve that the abline gets invisible in proximity of the legend? This should be achievable by setting the legend background white, without borders, but…
biotom
  • 701
  • 1
  • 6
  • 8
62
votes
6 answers

How can I remove the legend title in ggplot2?

I have a question concerning the legend in ggplot2. Say I have a hypothetical dataset about mean carrot length for two different colours at two…
susjoh
  • 2,298
  • 5
  • 20
  • 20
62
votes
1 answer

R ggplot2 legend inside the figure

So, I have the following data.frame, and I want to generate two plots in one graph for yval vs. xval, for each zval and type tp. The lef > df xval yval se zval cond 1 1.0 1.831564e-02 1.831564e-03 0 a 2 1.2…
Vahid Mirjalili
  • 6,211
  • 15
  • 57
  • 80
59
votes
3 answers

Styling part of label in legend in matplotlib

Is it possible to have part of the text of a legend in a particular style, let's say, bold or italic?
englebip
  • 955
  • 1
  • 11
  • 17
57
votes
5 answers

Reverse the order of a legend

I use the following code to plot the bar graph and need to present a legend in reverse order. How can I do it? colorsArr = plt.cm.BuPu(np.linspace(0, 0.5, len(C2))) p = numpy.empty(len(C2), dtype=object) plt.figure(figsize=(11, 11)) prevBar = 0 for…
YAKOVM
  • 9,805
  • 31
  • 116
  • 217
56
votes
3 answers

How to change the legend edgecolor and facecolor

Is there while rcParams['legend.frameon'] = 'False' a simple way to fill the legend area background with a given colour. More specifically I would like the grid not to be seen on the legend area because it disturbs the text reading. The keyword…
user1850133
  • 2,833
  • 9
  • 29
  • 39
56
votes
3 answers

Is it possible to add a string as a legend item

I am producing some plots in matplotlib and would like to add explanatory text for some of the data. I want to have a string inside my legend as a separate legend item above the '0-10' item. Does anyone know if there is a possible way to do…
Osmond Bishop
  • 7,560
  • 14
  • 42
  • 51