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.

legend
168 votes
4 answers
538k 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
133 votes
4 answers
151k views

Remove extra legends in ggplot2

I have a simple data frame that I'm trying to do a combined line and point plot using ggplot2. Supposing my data looks like this: df <- data.frame(x=rep(1:10,2), y=c(1:10,11:20), ...
Wilduck's user avatar
  • 14k
130 votes
4 answers
56k views

Keep unused levels in bar plot

I want to plot unused levels (that is, levels where the count is 0) in my bar-plot, however, unused levels are dropped and I cannot figure out how to keep them df <- data.frame(type=c("A", "A", "A"...
Ulrik's user avatar
  • 1,625
123 votes
2 answers
145k views

Legend on bottom, two rows wrapped in ggplot2 in r

library(ggplot2) library(scales) library(reshape2) Rdates <- c("2007-01-31","2007-02-28","2007-03-30","2007-04-30","2007-05-31","2007-06-29&...
Trevor Nederlof's user avatar
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,078
116 votes
10 answers
164k views

Plot labels at ends of lines

I have the following data (temp.dat see end note for full data) Year State Capex 1 2003 VIC 5.356415 2 2004 VIC 5.765232 3 2005 VIC 5.247276 4 2006 VIC 5.579882 5 2007 VIC ...
Hugh's user avatar
  • 15.9k
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
114 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,171
114 votes
4 answers
150k views

How to move or position a legend in ggplot2

I'm trying to create a ggplot2 plot with the legend beneath the plot. The ggplot2 book says on p 112 "The position and justification of legends are controlled by the theme setting legend.position, ...
Dan Goldstein's user avatar
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
100 votes
8 answers
211k views

Move seaborn plot legend to a different position

I'm using factorplot(kind="bar") with seaborn. The plot is fine except the legend is misplaced: too much to the right, text goes out of the plot's shaded area. How do I make seaborn place the legend ...
user124114's user avatar
  • 8,548
96 votes
5 answers
374k views

Matplotlib scatter plot legend

I created a 4D scatter plot graph to represent different temperatures in a specific area. When I create the legend, the legend shows the correct symbol and color but adds a line through it. The code I'...
user2386081's user avatar
  • 1,097
96 votes
5 answers
164k views

HighCharts Hide Series Name from the Legend

I try to solve this problem several times and give up. Now, when I have met him again, I decided to ask for some help. I have this code for my Legend: legend: { layout: 'vertical', align: '...
gotqn's user avatar
  • 43.4k

15 30 50 per page