第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何向seaborn點(diǎn)圖添加數(shù)據(jù)標(biāo)簽?

如何向seaborn點(diǎn)圖添加數(shù)據(jù)標(biāo)簽?

長(zhǎng)風(fēng)秋雁 2023-09-12 15:49:05
下面的代碼創(chuàng)建一個(gè)分類圖,其頂部有一個(gè)點(diǎn)圖,其中點(diǎn)圖顯示每個(gè)類別的平均值和 95% 置信區(qū)間。我需要將平均數(shù)據(jù)標(biāo)簽添加到圖中,但我不知道該怎么做。僅供參考,每個(gè)類別都有數(shù)千個(gè)點(diǎn),因此我不想標(biāo)記每個(gè)數(shù)據(jù)點(diǎn),而只想標(biāo)記estimator=np.mean點(diǎn)圖中的值。這可能嗎??我在此處創(chuàng)建了一個(gè)示例數(shù)據(jù)集,以便您可以復(fù)制并粘貼代碼并自行運(yùn)行。import pandas as pdimport seaborn as snsimport matplotlib.pyplot as pltimport matplotlib.ticker as mtickimport numpy as npd = {'SurfaceVersion': ['v1', 'v1', 'v1', 'v2', 'v2', 'v2', 'v3', 'v3', 'v3'],        'Error%': [.01, .03, .15, .28, .39, .01, .01, .06, .09]}df_comb =  pd.DataFrame(data=d)plotHeight = 10plotAspect = 2 #create catplot with jitter per surface version:ax = sns.catplot(data=df_comb, x='SurfaceVersion', y='Error%', jitter=True, legend=False, zorder=1, height=plotHeight, aspect=plotAspect)ax = sns.pointplot(data=df_comb, x='SurfaceVersion', y='Error%', estimator=np.mean, ci=95, capsize=.1, errwidth=1, hue='SurfaceVersion', color='k',zorder=2, height=plotHeight, aspect=plotAspect, join=False)ax.yaxis.set_major_formatter(mtick.PercentFormatter(xmax=1.0))plt.gca().legend().set_title('')plt.grid(color='grey', which='major', axis='y', linestyle='--')plt.xlabel('Surface Version')plt.ylabel('Error %')plt.subplots_adjust(top=0.95, left=.05)plt.suptitle('Error%')plt.legend([],[], frameon=False)                #This is to get rid of the legend that pops up with the seaborn plot b/c it's buggy.plt.axhline(y=0, color='r', linestyle='--')plt.show()
查看完整描述

1 回答

?
MYYA

TA貢獻(xiàn)1868條經(jīng)驗(yàn) 獲得超4個(gè)贊

您可以預(yù)先計(jì)算平均值并在循環(huán)中添加標(biāo)簽。請(qǐng)記住,就定位而言,x 值實(shí)際上只是 0、1、2。


mean_df = df_comb.groupby("SurfaceVersion")[["Error%"]].mean()


for i, row in enumerate(mean_df.itertuples()):


    x_value, mean = row

    

    plt.annotate(

        round(mean, 2),               # label text

        (i, mean),                    # (x, y)

        textcoords="offset points",   

        xytext=(10, 0),               # (x, y) offset amount

        ha='left')

https://img1.sycdn.imooc.com//650018260001af5119940983.jpg

查看完整回答
反對(duì) 回復(fù) 2023-09-12
  • 1 回答
  • 0 關(guān)注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)