【发布时间】:2022-12-13 18:28:15
【问题描述】:
我正在为我的公司编写自定义 matplotlib 样式表。除其他事项外,我正在尝试更改箱线图线条的颜色。以下示例使用字典更改 rcParams。使用 matplotlib 构建的标准图具有正确的颜色,而在 seaborn 图中似乎只有一些参数发生了变化。我如何强制 seaborn 使用我的样式表?
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df_penguins = pd.read_csv(
"https://raw.githubusercontent.com/mwaskom/seaborn-data/master/penguins.csv"
)
ex = {
'boxplot.boxprops.color': 'hotpink',
'boxplot.notch': True,
'boxplot.patchartist': False,
'boxplot.showbox': True,
'boxplot.showcaps': True,
'boxplot.showfliers': True,
'boxplot.showmeans': False,
'boxplot.vertical': True,
'boxplot.whiskerprops.color': 'hotpink',
'boxplot.whiskerprops.linestyle': '--',
'boxplot.whiskerprops.linewidth': 1.0,
'boxplot.whiskers': 1.5,
}
plt.rcParams.update(**ex)
fig, (ax1, ax2) = plt.subplots(
ncols=2,
sharey=True,
figsize=plt.figaspect(0.5)
)
sns.boxplot(data=df_penguins, y="body_mass_g", ax=ax1)
ax2.boxplot(df_penguins.body_mass_g.dropna())
plt.show()
【问题讨论】:
-
什么是期望的输出?
-
seaborn 箱线图通常不会从 matplotlib rcparams 中读取(否则默认情况下它们看起来不会有什么不同)。
标签: python matplotlib seaborn