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

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

將箱線圖排列為具有 seaborn 'FacetGrid' 的網格

將箱線圖排列為具有 seaborn 'FacetGrid' 的網格

不負相思意 2022-08-02 17:32:24
我有一個包含三列的數據框。我想為每個網絡設置一個框圖,按軸的“特征”和 CV 折疊進行分組(參見示例圖像)。Features, CV-fold, Accuracy, Networkdf = pd.read_csv(path)df['Features'] = df["Features"].astype('category')ordered_features = sorted(df.Network.value_counts().index)df = df.loc[df['Accuracy'] > 0.1]df.Accuracy = df.Accuracy*100#sns.color_palette("husl", len(df['CV-fold'].value_counts().index))#sns.set_palette('husl', len(df['CV-fold'].value_counts().index))g = sns.FacetGrid(df, row="Network", row_order=ordered_features,                  height=3, aspect=3, legend_out=True, despine=False)g.map(sns.boxplot, x="CV-fold", y="Accuracy", hue="Features", data=df, palette='muted').add_legend()g.set_axis_labels("", "Accuracy (%)")因為我有8個不同的網絡,所以我不想將它們全部放在一列或一行中,而是格式化為網格(例如2x4)。此外,即使未啟用,x 軸也僅在最底部的圖形中標記。sharex我該怎么做?
查看完整描述

1 回答

?
米脂

TA貢獻1836條經驗 獲得超3個贊

您可以使用關鍵字參數在具有多列的多行上獲取繪圖。col_wrap


要重復 x 軸標簽,請使用 。ax.tick_params()


例:


import seaborn as sns, matplotlib.pyplot as plt


tips = sns.load_dataset('tips')

ordered_days = sorted(tips['day'].unique())

g = sns.FacetGrid(tips,col='day',col_order=ordered_days,col_wrap=2)

#                                               change this to 4 ^

g.map(sns.boxplot,'sex','total_bill',palette='muted')

for ax in g.axes.flatten(): 

    ax.tick_params(labelbottom=True)

plt.tight_layout()

plt.show()

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

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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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