【发布时间】:2022-01-18 03:15:29
【问题描述】:
我正在使用下面这个简单的代码在 seaborn 中绘制数据:
df = pd.DataFrame([['A','car',10,1],
['A','plane',15,1],
['A','bike',25,3],
['B','plane',20,2],
['C','bike',30,3]],
columns = ['x','type','y', 'y_err'])
print(df)
fig, axes = plt.subplots(figsize=(5, 5))
sns.set_theme(style="darkgrid")
g = sns.barplot(
ax = axes, data=df,
x="x", y='y', hue="type",
palette="dark", alpha=.6
)
这是输出
当我尝试插入自定义错误栏时遇到问题,在 sns.barplot 函数中添加 yerr=df['y_err']。
问题是:
ValueError: The lengths of the data (3) and the error 5 do not match
我使用 seaborn 是因为我需要根据上面示例中的特定 x 绘制不同数量的条形图。
【问题讨论】:
标签: python matplotlib seaborn