第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何根據(jù) python/matplotlib 中的 pandas df 列名稱/標(biāo)簽名稱指定箱形

如何根據(jù) python/matplotlib 中的 pandas df 列名稱/標(biāo)簽名稱指定箱形

喵喵時(shí)光機(jī) 2023-07-11 15:08:23
我在子圖中有一系列箱形圖(見圖),但想根據(jù) DUT1 或 DUT2 更改每個(gè)單獨(dú)圖的標(biāo)簽顏色。以下是用于制作箱線圖的 df 之一的示例。每個(gè)圖都是使用類似的 df 繪制的,但包括來自各個(gè)設(shè)定點(diǎn)的測(cè)量值。      DUT1 A   DUT1 B   DUT2 A   DUT2 B527  0.92342  0.96342  0.98342  1.00342528  0.92754  0.88754  0.97754  0.97754529  0.93655  0.95655  0.99655  0.91655上面的每個(gè)數(shù)字都是 DUT 傳感器與參考傳感器在指定設(shè)定點(diǎn)的每次測(cè)量之間的差異。這是我如何創(chuàng)建箱形圖的每個(gè)子圖的快照。fig, axes = plt.subplots(ncols = 4, nrows = 2, sharey = True, figsize = (10,6))fig.add_subplot(111, frame_on = False)plt.tick_params(labelcolor = 'none', bottom = False, left = False)plt.ylabel('Difference from Reference PRT in $^\circ$F', labelpad=20)boxplot1 = df_setpoint1.boxplot(column = ['DUT1 A','DUT1 B','DUT2 A','DUT2 B'], ax = axes[1,0], rot=45)boxplot2 = df_setpoint2.boxplot(column = ['DUT1 A','DUT1 B','DUT2 A','DUT2 B'], ax = axes[1,1], rot=45)axes[1,0].set_title('Set Point -38.5$^\circ$F')axes[1,1].set_title('Set Point -25$^\circ$F')fig.suptitle('Temperature Distribution for Temperature Accuracy Testing')plt.tight_layout()plt.show()經(jīng)過一番搜索后,我在弄清楚如何指定每個(gè)圖標(biāo)簽的顏色時(shí)遇到了問題,因?yàn)槲也皇菃为?dú)創(chuàng)建每個(gè)箱形圖,而是從每個(gè)數(shù)據(jù)幀中的指定列創(chuàng)建。我遇到了很多盒子的自定義填充顏色并添加帶有自定義顏色的圖例,但我只想控制 x 軸上文本標(biāo)簽的顏色。
查看完整描述

1 回答

?
繁星點(diǎn)點(diǎn)滴滴

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()

http://img1.sycdn.imooc.com//64ad002b0001267e09390560.jpg

查看完整回答
反對(duì) 回復(fù) 2023-07-11
  • 1 回答
  • 0 關(guān)注
  • 141 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)