我有一個包含三列的數據框。我想為每個網絡設置一個框圖,按軸的“特征”和 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()

添加回答
舉報
0/150
提交
取消
