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
42
votes
2 answers

How to increase the font size of the legend in seaborn

I have the following codes to create a Seaborn strip plot. I am having a hard time figuring out how to increase the font size of the legend appearing in the plot. g=sns.stripplot(x="Market", y="Rate", hue="Group",data=myBenchmarkData, jitter=True,…
user3115933
  • 4,303
  • 15
  • 54
  • 94
42
votes
3 answers

How to create a draggable legend in matplotlib?

I'm drawing a legend on an axes object in matplotlib but the default positioning which claims to place it in a smart place doesn't seem to work. Ideally, I'd like to have the legend be draggable by the user. How can this be done?
Adam Fraser
  • 6,255
  • 10
  • 42
  • 54
41
votes
10 answers

How to position the legend inside a fieldset with a border?

According to the several references on the web, it is not possible to position a legend. So it is suggested to wrap it with span: Foo Then we can position the span inside the fieldset. but then when I want to add a…
nocss guy
  • 413
  • 1
  • 4
  • 4
41
votes
1 answer

How to adjust space between legend markers and labels

I want to adjust space between legend markers and labels. Sometime the space is too much as default. Does anyone know how to do this? Thanks.
rhtica
  • 545
  • 1
  • 5
  • 5
41
votes
1 answer

R: legend with points and lines being different colors (for the same legend item)

Using the legend() function is it possible to have the point and line be different colors? I feel like I'm missing something fairly obvious. The pt.bg option can change the background color, but I'm not seeing a pt.fg option The arises in the case…
Simon
  • 741
  • 1
  • 6
  • 11
40
votes
6 answers

How to show legend for only a specific subset of curves in the plotting?

t = 0 : 0.01 : 2 * pi; s = sin(t); c = cos(t); m = -sin(t); hold on; plot(t, s, 'r'); plot(t, c, 'b'); plot(t, m, 'g'); hold off; legend('', 'cosine', ''); There are several curves in my plotting. I want to display legend for only some of them.…
hkBattousai
  • 10,583
  • 18
  • 76
  • 124
38
votes
4 answers

R legend placement in a plot

I have a plot that has data that runs into the area I'd like to use for a legend. Is there a way to have the plot automatically put in something like a header space above the highest data points to fit the legend into? I can get it to work if I…
screechOwl
  • 27,310
  • 61
  • 158
  • 267
38
votes
2 answers

Matplotlib legend, add items across columns instead of down

For a simple plot below, is there a way to make matplotlib populate the legend so that it fills the rows left to right, instead of first column then second column? >>> from pylab import * >>> x = arange(-2*pi, 2*pi, 0.1) >>> plot(x, sin(x),…
jonathanbsyd
  • 8,031
  • 6
  • 24
  • 26
36
votes
2 answers

Position legend in first plot of facet

I would like to put my plot legend inside the plot, inside the first plot of a facet. Here is some example code: df=data.frame( x=runif(10), y=runif(10), facet=rep(c("a","b"),5), …
jslefche
  • 4,379
  • 7
  • 39
  • 50
36
votes
2 answers

Add custom legend without any relation to the graph

I wish to insert a legend that is not related to the graph whatsoever: figure; hold on; plot(0,0,'or'); plot(0,0,'ob'); plot(0,0,'ok'); leg = legend('red','blue','black'); Now I wish to add it to another…
jarhead
  • 1,821
  • 4
  • 26
  • 46
36
votes
2 answers

pandas pie chart plot remove the label text on the wedge

the pie chart example on pandas plotting tutorial http://pandas.pydata.org/pandas-docs/version/0.15.0/visualization.html generates the following figure: with this code: import matplotlib.pyplot as plt plt.style.use('ggplot') import numpy as…
fast tooth
  • 2,317
  • 4
  • 25
  • 34
36
votes
6 answers

ggplot2: Divide Legend into Two Columns, Each with Its Own Title

I have these factors require(ggplot2) names(table(diamonds$cut)) # [1] "Fair" "Good" "Very Good" "Premium" "Ideal" which I want to visually divide into two groups in the legend (indicating also the group name): "First group" -> "Fair",…
CptNemo
  • 6,455
  • 16
  • 58
  • 107
36
votes
2 answers

How to adjust the size of matplotlib legend box

I have a graph whose left upper corner is quite blank. So I decide to put my legend box there. However, I find the items in legend are very small and the legend box itself is also quite small. By "small", I mean something like this How can I make…
Sibbs Gambling
  • 19,274
  • 42
  • 103
  • 174
35
votes
2 answers

Why won't my element display inline?

I am trying to apply display: inline; to the element in my
element, so that the following will follow on the same line, but my CSS is having no effect. legend{ display: inline; } span { display:…
Mild Fuzz
  • 29,463
  • 31
  • 100
  • 148
35
votes
9 answers

pyplot combine multiple line labels in legend

I have data that results in multiple lines being plotted, I want to give these lines a single label in my legend. I think this can be better demonstrated using the example below, a = np.array([[ 3.57, 1.76, 7.42, 6.52], [ 1.57, 1.2…
hashmuke
  • 3,075
  • 2
  • 18
  • 29