文章目录

1. 图片

图片示例如下所示:
利用python绘制多个箱型图-LMLPHP

2. 代码

代码如下所示:

# Define the custom order based on atmospheric stability
custom_order = ['vus_0', 'us_1', 'ne_2', 'ws_3', 'ws_4', 's_5', 's_6', 's_7', 'vs_8', 'vs_9']

# Step 1: Reorder the statistical summary based on the custom order
grouped_stats_reordered = grouped_stats.loc[custom_order]

# Show only a truncated view to not overwhelm the user
grouped_stats_reordered.iloc[:, :8]  # Show only some of the columns for a preview
# Step 2: Reorder the boxplots based on the custom order

# Set the figure size
plt.figure(figsize=(15, 10))

# Subplot for class1
plt.subplot(2, 2, 1)
sns.boxplot(x='MO_label', y='class1', data=df, order=custom_order)
plt.title('Boxplot of class1 grouped by MO_label (Ordered by Atmospheric Stability)')

# Subplot for class5
plt.subplot(2, 2, 2)
sns.boxplot(x='MO_label', y='class5', data=df, order=custom_order)
plt.title('Boxplot of class5 grouped by MO_label (Ordered by Atmospheric Stability)')

# Subplot for ws120_Avg
plt.subplot(2, 2, 3)
sns.boxplot(x='MO_label', y='ws120_Avg', data=df, order=custom_order)
plt.title('Boxplot of ws120_Avg grouped by MO_label (Ordered by Atmospheric Stability)')

# Subplot for TI
plt.subplot(2, 2, 4)
sns.boxplot(x='MO_label', y='TI', data=df, order=custom_order)
plt.title('Boxplot of TI grouped by MO_label (Ordered by Atmospheric Stability)')

# Adjust layout
plt.tight_layout()
plt.show()
11-01 10:14