使用不同的数据进行传说matplotlib
我正在尝试创建与数据框架中其他数据相对应的传奇,而不是用于创建条形图的列。 我的理解是,Matplotlib Legend使用数据输入来分配传说,因为我输入一列(x)和一列(y),所以我只会得到一个传说。 我正在尝试将“位置”列用作我的传奇输入,以便我将有3个传奇输入['bot','mid','top'],并分配了各自的条。不确定如何。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'wins': [8,6,2],
'player': ['x','y','z'],
'position' : ['bot', 'mid', 'top'],
'color': ['red', 'blue', 'green']})
bar = plt.bar(df["player"], df["wins"], color = (df["color"]))
bar = plt.legend(labels =df['position'])
I'm trying to create a legend that corresponds to other data in dataframe rather than the column used to create the bar plot.
My understanding is that matplotlib legend, uses the data input to assign legends, since I enter one column (x) and one column (y) I get one legends only.
I'm trying to use the "position "column as my legend input, such that I'll have 3 legends inputs ['bot','mid','top'] with their respective bars assigned. Not sure how.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'wins': [8,6,2],
'player': ['x','y','z'],
'position' : ['bot', 'mid', 'top'],
'color': ['red', 'blue', 'green']})
bar = plt.bar(df["player"], df["wins"], color = (df["color"]))
bar = plt.legend(labels =df['position'])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用Seaborn,将其写为:
Using seaborn, one would write this as: