legend

How to add bar and line under the same label in a legend?

扶醉桌前 提交于 2021-02-04 19:04:03
问题 I made a plot with 2 Y axes, where one has a bar chart and the other one lines and I would like to add a common legend for both plots. If I add the following: axis1.legend([(bar1, line1), (bar2, line2)], ['Solution 1', 'Solution 2'], loc='upper left', numpoints=1) I almost get what I want, except for the markers / artists (not sure which term is suitable here), which are overlapping for both solutions as seen here: Is it possible to have the bar artist first and the line artist second, side

legend alignment in matplotlib

一曲冷凌霜 提交于 2021-02-04 18:39:44
问题 I'm trying to get labels left-aligned and values right-aligned in the legend. In below code, I've tried with format method, but the values are not properly aligned. Any hint/suggestions is greatly appreciated. import matplotlib.pyplot as pl # make a square figure and axes pl.figure(1, figsize=(6,6)) labels = 'FrogsWithTail', 'FrogsWithoutTail', 'DogsWithTail', 'DogsWithoutTail' fracs = [12113,8937,45190, 10] explode=(0, 0.05, 0, 0) pl.pie(fracs, explode=explode, labels=labels, autopct='%1.1f%

matplotlib bar plot add legend from categories dataframe column

。_饼干妹妹 提交于 2021-02-04 13:21:53
问题 I try to add the legend which should, according to my example, output: a red square with the word fruit and a green square with the word veggie. I tried several things (the example below is just 1 of the many trials), but I can't get it work. Can someone tell me how to solve this problem? import pandas as pd from matplotlib import pyplot as plt data = [['apple', 'fruit', 10], ['nanaba', 'fruit', 15], ['salat','veggie', 144]] data = pd.DataFrame(data, columns = ['Object', 'Type', 'Value'])

Text alignment using format in matplotlib legend

不打扰是莪最后的温柔 提交于 2021-01-29 18:37:30
问题 I'm trying to get two words aligned in a legend in matplotlib. With the print statement I can do this using the tools available to format (< for left alignment, > for right alignment), but in the legend this has a different result. import matplotlib.pyplot as plt import numpy as np str1 = r'{:<18} {:>12}'.format('HadGEM2-ES'+',', r'$\lambda$') str2 = r'{:<18} {:>12}'.format('inmcm4'+',', r'$\lambda$') print(str1) print(str2) plt.plot(np.arange(10), label=str1) plt.plot(0.8*np.arange(10),

Need to add legend and fix axis in ggplot [duplicate]

六月ゝ 毕业季﹏ 提交于 2021-01-29 17:22:04
问题 This question already has answers here : Add legend to ggplot2 line plot (3 answers) Closed 22 days ago . I'm new to ggplot and I'm trying to figure out how to add a legend to a graph and re-label the x-axis. I've enclosed the plotting code and resulting graph . I would like to add a legend that explains what the blue line and the green and red dots are. I would also like the years on the x-axis to appear as 2018, 2019, ... , 2020 instead of 2017.5, 2010.0, ..., 2020.0. I can't find a

Assemble Legend for Many Curves

南楼画角 提交于 2021-01-29 16:53:13
问题 I need to assemble a Matlab/Octave legend for indexed curves, and I found the following example which seems to work well: legend(strcat("curve ", num2str(1:2))) Associates the labels "curve 1" and "curve 2" with the two curves given. However, if I need to add a different, non-indexed type of curve, the method above seems not to work anymore. legend(strcat("curve ", num2str(1:2)),"another curve") In the second example the first curve has for legend ["curve 1"; "curve 2"], and the second curve

Bokeh Position Legend outside plot area for stacked vbar

巧了我就是萌 提交于 2021-01-29 12:50:43
问题 I have a stacked vbar chart in Bokeh, a simplified version of which can be reproduced with: from bokeh.plotting import figure from bokeh.io import show months = ['JAN', 'FEB', 'MAR'] categories = ["cat1", "cat2", "cat3"] data = {"month" : months, "cat1" : [1, 4, 12], "cat2" : [2, 5, 3], "cat3" : [5, 6, 1]} colors = ["#c9d9d3", "#718dbf", "#e84d60"] p = figure(x_range=months, plot_height=250, title="Categories by month", toolbar_location=None) p.vbar_stack(categories, x='month', width=0.9,

Use one column for color and an other one for legend in ggplot2

僤鯓⒐⒋嵵緔 提交于 2021-01-29 07:23:19
问题 I have a data frame with 5 variable as : head(drop(rast.df)) Longitude Latitude Values Color 1 -15.10068 16.68171 32 #98d604 2 -15.08271 16.68171 32 #98d604 3 -14.99288 16.68171 32 #98d604 4 -14.97492 16.68171 32 #98d604 5 -14.95695 16.68171 32 #98d604 6 -15.11865 16.66375 32 #98d604 Main 1 Sparse Herbaceous: dominated by herbaceous annuals (<2m) 10-60% cover. 2 Sparse Herbaceous: dominated by herbaceous annuals (<2m) 10-60% cover. 3 Sparse Herbaceous: dominated by herbaceous annuals (<2m) 10

Adding a legend to a combined line and bargraph ggplot

随声附和 提交于 2021-01-29 06:40:54
问题 So I know many people have asked similar questions but the code others have used does not seem to be working for my graph hence why I'm wondering if I have done something wrong. I have this code: ggplot(dfMonth) + geom_col(aes(x=Month, y=NumberMO), size=.7, colour="black", fill="white") + geom_line(aes(x=Month, y=NumberME), size=1, colour="black", group=1) + xlab("Month") + ylab("No. of birds observed") + theme_bw() + geom_point(x=Month, y=NumberME) + scale_colour_manual("" ,values =c(

How can I separate legends in ggplot2 so they don't overlap?

自闭症网瘾萝莉.ら 提交于 2021-01-29 05:24:06
问题 I cannot figure out how to make two separate legends for my geom_point and my geom_line data. Currently, I have a legend describing what the different linetypes mean, but when I try to add a legend to describe what the different point shapes mean (blue triangles and circles), blue circles simply overlap the linetype legend. Many thanks to anyone who can help me make two separate legends for linetype and point shape. Below is my code, my data, and a picture of my current graph: Here's my data,