legend

Horizontally align bar plot legends in python

大憨熊 提交于 2020-01-22 19:30:05
问题 I have made a multi axis graph using the following code and I am unable to arrange the legend as I want. The code of my graph is as follows: import matplotlib.pyplot as plt import numpy as np x = np.arange(4) y = [5, 7, 4, 9] z = [9, 3, 5, 6] r = [30, 40, 45, 37] fig,ax = plt.subplots() abc = ax.bar(x,y,0.25 ) cde = ax.bar(x+0.25,z,0.25) ax.legend((abc[0], cde[0]), ('y', 'z'),bbox_to_anchor=(0., 1.02, 1, .102) , borderaxespad=0.) ax.set_xticks(x + 0.25 / 2) ax.set_xticklabels(('A', 'B', 'C',

Python Matplotlib Multi-color Legend Entry

元气小坏坏 提交于 2020-01-22 14:31:09
问题 I would like to make a legend entry in a matplotlib look something like this: It has multiple colors for a given legend item. Code is shown below which outputs a red rectangle. I'm wondering what I need to do to overlay one color ontop of another? Or is there a better solution? import matplotlib.patches as mpatches import matplotlib.pyplot as plt red_patch = mpatches.Patch(color='red', label='Foo') plt.legend(handles=[red_patch]) plt.show() 回答1: The solution I am proposing is to combine two

How to change legend size with matplotlib.pyplot

五迷三道 提交于 2020-01-18 11:16:45
问题 Simple question here: I'm trying to get the size of my legend using matplotlib.pyplot to be smaller (i.e., the text to be smaller). The code I'm using goes something like this: plot.figure() plot.scatter(k, sum_cf, color='black', label='Sum of Cause Fractions') plot.scatter(k, data[:, 0], color='b', label='Dis 1: cf = .6, var = .2') plot.scatter(k, data[:, 1], color='r', label='Dis 2: cf = .2, var = .1') plot.scatter(k, data[:, 2], color='g', label='Dis 3: cf = .1, var = .01') plot.legend(loc

How to change legend size with matplotlib.pyplot

百般思念 提交于 2020-01-18 11:13:24
问题 Simple question here: I'm trying to get the size of my legend using matplotlib.pyplot to be smaller (i.e., the text to be smaller). The code I'm using goes something like this: plot.figure() plot.scatter(k, sum_cf, color='black', label='Sum of Cause Fractions') plot.scatter(k, data[:, 0], color='b', label='Dis 1: cf = .6, var = .2') plot.scatter(k, data[:, 1], color='r', label='Dis 2: cf = .2, var = .1') plot.scatter(k, data[:, 2], color='g', label='Dis 3: cf = .1, var = .01') plot.legend(loc

How to change legend size with matplotlib.pyplot

a 夏天 提交于 2020-01-18 11:12:11
问题 Simple question here: I'm trying to get the size of my legend using matplotlib.pyplot to be smaller (i.e., the text to be smaller). The code I'm using goes something like this: plot.figure() plot.scatter(k, sum_cf, color='black', label='Sum of Cause Fractions') plot.scatter(k, data[:, 0], color='b', label='Dis 1: cf = .6, var = .2') plot.scatter(k, data[:, 1], color='r', label='Dis 2: cf = .2, var = .1') plot.scatter(k, data[:, 2], color='g', label='Dis 3: cf = .1, var = .01') plot.legend(loc

How to change legend size with matplotlib.pyplot

[亡魂溺海] 提交于 2020-01-18 11:12:07
问题 Simple question here: I'm trying to get the size of my legend using matplotlib.pyplot to be smaller (i.e., the text to be smaller). The code I'm using goes something like this: plot.figure() plot.scatter(k, sum_cf, color='black', label='Sum of Cause Fractions') plot.scatter(k, data[:, 0], color='b', label='Dis 1: cf = .6, var = .2') plot.scatter(k, data[:, 1], color='r', label='Dis 2: cf = .2, var = .1') plot.scatter(k, data[:, 2], color='g', label='Dis 3: cf = .1, var = .01') plot.legend(loc

Matplotlib scatter plot with legend

强颜欢笑 提交于 2020-01-18 09:50:15
问题 I want to create a Matplotlib scatter plot, with a legend showing the colour for each class. For example, I have a list of x and y values, and a list of classes values. Each element in the x , y and classes lists corresponds to one point in the plot. I want each class to have its own colour, which I have already coded, but then I want the classes to be displayed in a legend. What paramaters do I pass to the legend() function to achieve this? Here is my code so far: x = [1, 3, 4, 6, 7, 9] y =

Matplotlib scatter plot with legend

给你一囗甜甜゛ 提交于 2020-01-18 09:50:09
问题 I want to create a Matplotlib scatter plot, with a legend showing the colour for each class. For example, I have a list of x and y values, and a list of classes values. Each element in the x , y and classes lists corresponds to one point in the plot. I want each class to have its own colour, which I have already coded, but then I want the classes to be displayed in a legend. What paramaters do I pass to the legend() function to achieve this? Here is my code so far: x = [1, 3, 4, 6, 7, 9] y =

Creating legend in geom_histogram for elements created from geom_vline

会有一股神秘感。 提交于 2020-01-16 18:47:50
问题 Here is an example data set: structure(list(Age = c(6L, 7L, 5L, 6L, 7L, 9L,6L, 7L, 5L, 6L, 7L, 9L,6L, 7L, 5L, 6L, 7L, 9L), Year = c(2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011 )), .Names = c("Age", "Year"), row.names = c(NA, 6L), class = "data.frame") I am trying to create a legend that will show the three components that I list in my geom_vline command below. I've read several examples on s.overflow but nothing seems to be

Creating legend in geom_histogram for elements created from geom_vline

无人久伴 提交于 2020-01-16 18:46:06
问题 Here is an example data set: structure(list(Age = c(6L, 7L, 5L, 6L, 7L, 9L,6L, 7L, 5L, 6L, 7L, 9L,6L, 7L, 5L, 6L, 7L, 9L), Year = c(2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011, 2011 )), .Names = c("Age", "Year"), row.names = c(NA, 6L), class = "data.frame") I am trying to create a legend that will show the three components that I list in my geom_vline command below. I've read several examples on s.overflow but nothing seems to be