1 回答

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊
雖然文本標(biāo)簽著色不是很方便,但后端的箱線圖著色matplotlib是可行的,需要在每個(gè)修補(bǔ)的藝術(shù)家之間循環(huán)。對(duì)于每個(gè)配對(duì)DUT1并與每個(gè)藝術(shù)家DUT2運(yùn)行 elementwsiezip循環(huán)。
下面使用 OP 提供的數(shù)據(jù)運(yùn)行一個(gè)子圖。為了避免重復(fù)行,請(qǐng)集成到定義的方法中并通過它運(yùn)行每個(gè)子圖,或添加頂層for以迭代數(shù)組中所有生成的子圖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()
添加回答
舉報(bào)