如何更改plt.boxplot的showmeans中均值标记的颜色?

时间:2019-04-01 21:20:39

标签: python matplotlib

我有一个图(下),其中有用

创建的均值标记
_http_outgoing.js:491
    throw new Error('Can\'t set headers after they are sent.');
    ^

Error: Can't set headers after they are sent.
    at validateHeader (_http_outgoing.js:491:11)
    at ServerResponse.setHeader (_http_outgoing.js:498:3)
    at Array.write (C:\Users\Rohit\Desktop\Project_me\soil2\node_modules\finalhandler\index.js:285:9)
    at listener (C:\Users\Rohit\Desktop\Project_me\soil2\node_modules\on-finished\index.js:169:15)
    at onFinish (C:\Users\Rohit\Desktop\Project_me\soil2\node_modules\on-finished\index.js:100:5)
    at callback (C:\Users\Rohit\Desktop\Project_me\soil2\node_modules\ee-first\index.js:55:10)
    at IncomingMessage.onevent (C:\Users\Rohit\Desktop\Project_me\soil2\node_modules\ee-first\index.js:93:5)
    at emitNone (events.js:106:13)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)

如何将下图中的绿色三角形更改为其他形状?我在上面使用了for group in df.groups.unique(): df_temp = df.loc[df["group"]==group]] ax = plt.plot(df_temp) plt.boxplot(df_temp, showmeans=True, meanprops={'color'=ax[0].get_color()}) ,但似乎并没有提到我认为的内容。

plot

1 个答案:

答案 0 :(得分:0)

由Paul H链接,我将meanprops的值更新为以下值以更改颜色:

for group in df.groups.unique():
df_temp = df.loc[df["group"]==group]]
ax = plt.plot(df_temp)

plt.boxplot(df_temp, showmeans=True, 
    meanprops={'markerfacecolor': ax[0].get_color(), 'markeredgecolor': ax[0].get_color()})

该图现在看起来像:

plot