pandas -boxplot中位数颜色设置问题 [英] pandas - boxplot median color settings issues
本文介绍了 pandas -boxplot中位数颜色设置问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行Pandas 0.16.2和Matplotlib 1.4.3.我遇到的问题是将以下代码生成的箱线图的中位数着色:
I'm running Pandas 0.16.2 and Matplotlib 1.4.3. I have this issue coloring the median of the boxplot generated by the following code:
df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
fig, ax = plt.subplots()
medianprops = dict(linestyle='-', linewidth=2, color='blue')
bp = df.boxplot(medianprops=medianprops)
plt.show()
返回:
似乎未读取color
设置.仅更改线型和线宽的设置,绘图即可正确反应.
It appears that the color
setting is not read. Changing only the settings of linestyle and linewidth the plot reacts correctly.
medianprops = dict(linestyle='-.', linewidth=5, color='blue')
任何人都可以复制它吗?
Anyone can reproduce it?
推荐答案
实际上,以下解决方法效果很好,可以从boxplot命令返回dict
:
Actually the following workaround works well, returning a dict
from the boxplot command:
df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
fig, ax = plt.subplots()
bp = df.boxplot(return_type='dict')
,然后使用以下方法将颜色和线宽直接分配给中位数:
and then assign directly colors and linewidth to the medians with:
[[item.set_color('r') for item in bp[key]['medians']] for key in bp.keys()]
[[item.set_linewidth(0.8) for item in bp[key]['medians']] for key in bp.keys()]
这篇关于 pandas -boxplot中位数颜色设置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文