1 回答
TA贡献1803条经验 获得超3个赞
虽然文本标签着色不是很方便,但后端的箱线图着色matplotlib是可行的,需要在每个修补的艺术家之间循环。对于每个配对DUT1并与每个艺术家DUT2运行 elementwsiezip循环。
下面使用 OP 提供的数据运行一个子图。为了避免重复行,请集成到定义的方法中并通过它运行每个子图,或添加顶层for以迭代数组中所有生成的子图axes。
import matplotlib.patches as mpatches
...
# BOX PLOT LEGEND
blue_patch = mpatches.Patch(color='blue', label='The red data')
green_patch = mpatches.Patch(color='green', label='The blue data')
fig.legend(handles=[blue_patch, green_patch], labels=['A', 'B'],
ncol=2, loc='upper center', bbox_to_anchor=(0.5, 0.95))
# BOX PLOT
boxplot1 = df_setpoint1.boxplot(column = ['DUT1 A','DUT1 B','DUT2 A','DUT2 B'],
ax=axes[1,0], patch_artist=True, rot=45)
# BOX PLOT COLORING
colors = ['blue', 'blue', 'green', 'green']
for i,(artist, col) in enumerate(zip(axes[1,0].artists, colors)):
artist.set_edgecolor(col)
artist.set_facecolor(col)
# Each box has 6 associated Line2D objects (to make the whiskers, fliers, etc.)
# Loop over them here, and use the same colour as above
for j in range(i*6,i*6+4):
line = axes[1,0].lines[j]
line.set_color(col)
line.set_mfc(col)
line.set_mec(col)
line.set_linewidth(0.5)
...
fig.tight_layout(rect=[0, 0.03, 1, 0.90])
plt.show()
添加回答
举报