我想从一个 excel 文件创建多个箱线图。我的问题是所有 boxex 都获得相同的颜色(深蓝色)但是我没有定义这种颜色! 这是我的代码,它指定了我想要什么颜色:
import pandas as pd
import matplotlib.pyplot as plt
# load the Excel file into a pandas dataframe
df = pd.read_excel('D:\Omid_TTU\RA\TASK5\selected1daybefore&after\GIS_Standard_format\FID_6_test2.xlsx')
# create a grid of subplots
fig, axs = plt.subplots(nrows=1, ncols=5, figsize=(20, 5))
# loop through each column and plot it in its own subplot
for i, col in enumerate(['Liq_depth_dim', 'TMP_air_temp', 'VIS_dist_dim', 'WND_dir_ang', 'WND_speed_rate']):
data = df[col].dropna()
axs[i].boxplot(data, patch_artist=True, notch=True, vert=False)
axs[i].set_title(col)
axs[i].set_yticklabels([])
color_list = ['red', 'lightyellow', 'green', 'slateblue2', 'steelblue1']
for patch, colormap in zip(axs[i].boxplot(data, patch_artist=True, notch=True, vert=False)['boxes'], color_list):
patch.set_facecolor(colormap)
for whisker in axs[i].boxplot(data, patch_artist=True, notch=True, vert=False)['whiskers']:
whisker.set(color='r', linewidth=3, linestyle=':')
for cap in axs[i].boxplot(data, patch_artist=True, notch=True, vert=False)['caps']:
cap.set(color='r', linewidth=2)
for median in axs[i].boxplot(data, patch_artist=True, notch=True, vert=False)['medians']:
median.set(color='g', linewidth=3)
for flier in axs[i].boxplot(data, patch_artist=True, notch=True, vert=False)['fliers']:
flier.set(marker='D', color='r', alpha=0.5)
# adjust the spacing between subplots
plt.subplots_adjust(wspace=0.5)
plt.show()
你能帮我解决这个问题吗?
我想从一个 excel 文件创建多个箱线图。我的问题是所有 boxex 都获得相同的颜色(深蓝色)但是我没有定义这种颜色!