Skip to main content

All Questions

337 votes
10 answers
377k 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
508 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
8 votes
2 answers
7k views

How to add a string as the artist to a legend

I am trying to create a legend in a python figure where the artist is a string (a single letter) which is then labelled. For example I would like a legend for the following figure: import numpy as np ...
Sean Elvidge's user avatar
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
27 votes
5 answers
80k views

Two geom_points add a legend

I plot a 2 geom_point graph with the following code: source("http://www.openintro.org/stat/data/arbuthnot.R") library(ggplot2) ggplot() + geom_point(aes(x = year,y = boys),data=arbuthnot,colour = '#...
S12000's user avatar
  • 3,376
0 votes
1 answer
6k views

How to add data table with legend keys to a MS Chart in C#?

There are 2 lists called listversion & MIN_list. Using values of these list I have created a line chart. Everything is work fine. But I am wondering whether it is possible to add a data table with ...
Sachith's user avatar
  • 201
61 votes
4 answers
106k views

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 ...
Osmond Bishop's user avatar
114 votes
4 answers
149k 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
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
10 votes
4 answers
11k views

Combine two patches for legend

I am trying to plot some data with confidence bands. I am doing this with two plots for each data stream: plot, and fill_between. I would like the legend to look similar to the plots, where each entry ...
Blink's user avatar
  • 1,494
35 votes
5 answers
44k views

How to make two markers share the same label in the legend

What I want is like this: What I get is this: So how to merge the markers into one label? also for the lines, for the lines, of course, u can realize it by not assigning label to the second line ...
user3737702's user avatar
13 votes
2 answers
17k views

How to add a legend for two geom layers in one ggplot2 plot?

I've got a data frame that looks like this: glimpse(spottingIntensityByMonth) # Observations: 27 # Variables: 3 # $ yearMonth <dttm> 2015-05-01, 2015-06-01, 2015-07-01, 2015-08-01, 2015-09-01, ...
hpy's user avatar
  • 2,101
5 votes
1 answer
16k views

ggplot2 draws two legends

I have almost complete the following graph, but there is one problem with it. The legend in the graph is drawn twice. Here is the data: structure(list(Period = c("January 1997 - August 2003", "...
user1738753's user avatar
33 votes
2 answers
152k views

Matplotlib automatic legend outside plot [duplicate]

I am trying to use the keyword bbox_to_anchor() in a matplotlib plot in Python. Here is a very basic plot that I have produced based on this example. : import matplotlib.pyplot as plt x = [1,2,3] ...
edesz's user avatar
  • 12.2k
2 votes
1 answer
2k views

matplotlib legend not working correctly with handles

Matplotlib can display a legend automatically or manually with giving it handles to the plots. But somehow the latter is not working correctly for me. Take this example: legend_handles = {} lgh, = ...
Bastiaan's user avatar
  • 4,602

15 30 50 per page