Skip to main content
The 2024 Developer Survey results are live! See the results

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.

94 votes
9 answers
48k views

Making a Legend/Key in GraphViz

I’d like to include a legend or key in my GraphViz diagram. I’m having trouble figuring out what code to use, though. I also want to put it in a corner, but the only coord I know for sure is the ...
Synetech's user avatar
  • 9,853
88 votes
6 answers
111k views

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(...
Gabriel's user avatar
  • 42.1k
88 votes
4 answers
149k views

creating over 20 unique legend colors using matplotlib

I am plotting 20 different lines on a single plot using matplotlib. I use a for loop for plotting and label every line with its key and then use the legend function for key in dict.keys(): plot(x,...
msohail's user avatar
  • 1,115
88 votes
4 answers
68k views

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's user avatar
  • 8,693
86 votes
8 answers
47k views

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, ...
Don Albrecht's user avatar
  • 1,282
79 votes
9 answers
148k views

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=...
Tapajit Dey's user avatar
  • 1,376
79 votes
1 answer
39k views

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 ...
baltazar's user avatar
  • 1,679
78 votes
4 answers
138k views

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]] ...
N.K.'s user avatar
  • 813
78 votes
9 answers
158k views

How do I assign multiple legend labels at once?

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, ...
Kit's user avatar
  • 31.2k
74 votes
4 answers
184k views

Remove line through legend marker with .plot

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', ...
jlconlin's user avatar
  • 14.8k
70 votes
2 answers
172k views

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 ...
biotom's user avatar
  • 751
68 votes
1 answer
49k views

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 ...
Vahid Mirjalili's user avatar
66 votes
3 answers
69k views

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's user avatar
  • 1,025
65 votes
6 answers
75k views

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 farms: carrots<-NULL carrots$Farm<-rep(c("X","Y")...
susjoh's user avatar
  • 2,388
63 votes
5 answers
56k views

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=...
YAKOVM's user avatar
  • 10.1k

15 30 50 per page