简体   繁体   English

在mplstyle或matplotlibrc中设置boxplot参数

[英]set boxplot parameters in mplstyle or matplotlibrc

There are numerous ways to change eg colors of boxplot elements. 有许多方法可以更改例如箱形图元素的颜色。 However, I prefer to set them for all my plots in a dedicated .mplstyle or in my matplotlibrc. 但是,我更喜欢使用专用的.mplstyle或matplotlibrc为所有情节设置它们。 Both methods appear to not change anything for boxplots, though. 不过,这两种方法似乎都不会改变箱型图。

Here is part of my own.mplstyle which should set the caps to yellow: 这是我自己的.mplstyle的一部分,应该将大写字母设置为黄色:

# Boxplots
boxplot.capprops.color: y
boxplot.capprops.linestyle: -
boxplot.capprops.linewidth: 1.0
boxplot.flierprops.color: y
boxplot.flierprops.linestyle: none
boxplot.flierprops.linewidth: 1.0
boxplot.flierprops.marker: x
boxplot.flierprops.markerfacecolor: auto

and part of my matplotlibrc which should set the caps to blue: 和我的matplotlibrc的一部分,应该将上限设置为蓝色:

boxplot.capprops.color     : b
#boxplot.capprops.linewidth : 1.0
# boxplot.capprops.linestyle : -

however, the following code leads to black caps: 但是,以下代码导致大写:

plt.style.use('own')
dataset.plot(kind='box')
plt.show()

figure: 数字:

在此处输入图片说明

also, is there a way to set cap size? 另外,有没有办法设置瓶盖尺寸?

Pandas ignores the rc settings for boxplots. Pandas忽略框线图的rc设置。 They work fine however for matplotlib boxplots. 但是,它们对于matplotlib箱图工作正常。

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.rcParams["boxplot.capprops.color"] = "red"

data = np.random.randn(20,5)
df = pd.DataFrame(data, columns=list("ABCDE"))

fig, (ax,ax2) = plt.subplots(ncols=2)
ax.set_title("matplotlib boxplot")
ax.boxplot(data)

ax2.set_title("pandas boxplot")
df.plot(kind="box", ax=ax2)

plt.show()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM