[英]I want to make vertical bars with values on top of each bar
the plot is horizontal without values I tried this code plot 是水平的,没有值我试过这段代码
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
g = sns.barplot(
x="score",
y="subject",
hue="pipeline",
#col="dataset",
data=results,
palette="viridis",
)
I tried this for values我试过这个值
ax = g.axes[0, 0]
ax.bar_label(ax.containers[0])
I had this error 'AxesSubplot' object is not subscriptable我有这个错误 'AxesSubplot' object is not subscriptable
You can try this by using the bar chart from pandas. If you want the plot horizontal use.barh If you provide a snippet from your df it would be easier to fit the data, though.您可以使用 pandas 中的条形图来尝试此操作。如果您想要 plot 水平 use.barh 如果您提供来自 df 的片段,那么拟合数据会更容易。 If you want to use a hue you can just pivot your data to the right format.如果您想使用色调,您只需将 pivot 数据转换为正确的格式即可。
ax = (df
.plot.bar(#insert your x and y
)
)
for c in ax.containers:
# Optional: if the segment is small or 0, customize the labels
labels = [v.get_height() if v.get_height() > 0 else '' for v in c]
# remove the labels parameter if it's not needed for customized labels
ax.bar_label(c, labels=labels, label_type='edge')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.