本文介绍了更改 pandas 中Boxplot的面色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更改使用pandas实用程序功能绘制的箱线图的颜色.我可以使用color参数更改大多数属性,但无法弄清楚如何更改框的facecolor.有人知道该怎么做吗?

I need to change the colors of the boxplot drawn using pandas utility function. I can change most properties using the color argument but can't figure out how to change the facecolor of the box. Someone knows how to do it?

import pandas as pd
import numpy as np
data = np.random.randn(100, 4)
labels = list("ABCD")
df = pd.DataFrame(data, columns=labels)
props = dict(boxes="DarkGreen", whiskers="DarkOrange", medians="DarkBlue", caps="Gray")
df.plot.box(color=props)

推荐答案

虽然我仍然建议在熊猫的绘图界面上使用seaborn和raw matplotlib,但事实证明,您可以将patch_artist=True作为kwarg传递给df.plot.box,会将其作为kwarg传递给df.plot,将作为kwarg传递给matplotlib.Axes.boxplot.

While I still recommend seaborn and raw matplotlib over the plotting interface in pandas, it turns out that you can pass patch_artist=True as a kwarg to df.plot.box, which will pass it as a kwarg to df.plot, which will pass is as a kwarg to matplotlib.Axes.boxplot.

import pandas as pd
import numpy as np
data = np.random.randn(100, 4)
labels = list("ABCD")
df = pd.DataFrame(data, columns=labels)
props = dict(boxes="DarkGreen", whiskers="DarkOrange", medians="DarkBlue", caps="Gray")
df.plot.box(color=props, patch_artist=True)

这篇关于更改 pandas 中Boxplot的面色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 05:06