![](/img/trans.png)
[英]how to remove empty space from bars for a specific group, that was plotted as seaborn bar plot on data in pandas dataframe
[英]How to Annotate Seaborn Bar Plot with separate values (dates) from col of Dataframe which is not plotted
I have a Pandas DataFrame where I have plot a Seaborn Bar Plot, as shown (edit: image not appearing).
我希望在每个条上注释 date_install 值。 我搜索了高低,只能看到用条本身的 y 值注释条的参考。
价格绘制在 y 轴上,part_no 绘制在 x 轴上。
这可能在 Seaborn 内吗?
谢谢
import pandas as pd
import seaborn as sns
data1 = {
'date_install': ['2020-02-02','2020-04-03', '2019-03-02'],
'part_no':['D235','S222','S211'],
'price': ['1500', '2000', '1600']
}
df = pd.DataFrame(data1)
sns.barplot(x=df.part_no, y=df.price)
import pandas as pd
import seaborn as sns
data1 = {
'date_install': ['2020-02-02','2020-04-03', '2019-03-02'],
'part_no':['D235','S222','S211'],
'price': ['1500', '2000', '1600']
}
df = pd.DataFrame(data1)
plt.figure()
ax = sns.barplot(x=df.part_no, y=df.price)
for p,date in zip(ax.patches, data1['date_install']):
ax.annotate(date, xy=(p.get_x()+p.get_width()/2, p.get_height()),
ha='center', va='bottom')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.