Seaborn 条形图,误差线仅在一个方向上

我正在使用 seaborn barplot 函数来绘制来自不同组的数据。是否可以仅在一个方向(仅向上但不能向下)绘制误差线?


这就是我所拥有的:


np.random.seed(2)

df = pd.DataFrame({'value': np.random.randint(0,100,20), 'group1': ['A','B']*10, 'group2': ['Y','Z']*5 + ['Z','Y']*5 })


fig, ax = plt.subplots(1,1,figsize=[5,6])

sns.barplot('group1','value','group2',data=df, ax=ax,capsize=.15, lw=1, edgecolor=".2", ci=68) # SEM errorbars

plt.show()

http://img2.mukewang.com/62a7e8a60001950d03230368.jpg

这就是我想要的:

http://img.mukewang.com/62a7e8b30001911e02920331.jpg


皈依舞
浏览 169回答 1
1回答

慕码人2483693

我在 seaborn 中看不到默认选项,但我们可以用zorderfig, ax = plt.subplots(1,1,figsize=[5,6])# plot the error bars# notice the zordersns.barplot('group1','value','group2',            data=df,             ax=ax,capsize=.15, zorder=5,            ci=68) # SEM errorbars# plot the mean bars# notice the zordersns.barplot('group1','value','group2',            data=df,             ax=ax, lw=1, edgecolor=".2",            zorder=10,            ci=None) # no CI errorbars# handle the duplicate legendhandles, labels = ax.get_legend_handles_labels()ax.legend(handles[-2:], labels[-2:], title='group2')plt.show()输出:
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python