亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Seaborn 條形圖,誤差線僅在一個方向上

Seaborn 條形圖,誤差線僅在一個方向上

皈依舞 2022-06-14 09:46:24
我正在使用 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 errorbarsplt.show()這就是我想要的:
查看完整描述

1 回答

?
慕碼人2483693

TA貢獻1860條經驗 獲得超9個贊

我在 seaborn 中看不到默認選項,但我們可以用zorder


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


# plot the error bars

# notice the zorder

sns.barplot('group1','value','group2',

            data=df, 

            ax=ax,capsize=.15, zorder=5,

            ci=68) # SEM errorbars


# plot the mean bars

# notice the zorder

sns.barplot('group1','value','group2',

            data=df, 

            ax=ax, lw=1, edgecolor=".2",

            zorder=10,

            ci=None) # no CI errorbars


# handle the duplicate legend

handles, labels = ax.get_legend_handles_labels()

ax.legend(handles[-2:], labels[-2:], title='group2')


plt.show()

輸出:

http://img1.sycdn.imooc.com//62a7e8c60001287903290367.jpg

查看完整回答
反對 回復 2022-06-14
  • 1 回答
  • 0 關注
  • 151 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號