我想通过样式表对箱线图的各个方面进行样式设置,并通过 plt.style.use("my_style") 应用定义的样式。因此,目标是通过代码“外包”图表的所有样式属性,并在样式中定义它们。
这只是文件的摘录:
### BoxPLots
boxplot.showmeans: True
boxplot.showcaps: True
boxplot.showbox: True
boxplot.showfliers: True
boxplot.meanline: True
boxplot.showmeans: True
boxplot.showcaps: True
boxplot.showbox: True
boxplot.showfliers: True
boxplot.meanline: True
# these color styles are parially applied
boxplot.medianprops.color: "red". # not applied
boxplot.medianprops.linestyle: solid. # applied
boxplot.meanprops.color: "yellow" # applied
boxplot.meanprops.linestyle: dashed. # applied
boxplot.boxprops.color: 'red' # not applied
boxplot.boxprops.linestyle: dotted # applied
其应用者:
df = pd.DataFrame(array, columns=['Values'])
plt.style.use("my_style")
bp = df.boxplot(column=['Values'],
capprops=dict(color='#ff5c00'),
flierprops=dict(marker='o', markeredgecolor='#fdfc60', markersize=10))
结果: 显示中线及其颜色,以及应用所有线型,但不应用框的颜色或中位数。
像 capprops 和 flierprops 这样的编程定义正在起作用。
样式表有一些语法错误。有些颜色不需要用“”指定,因此会被忽略:
试试这个:
### Custom BoxPlot Style
# General BoxPlot Settings
boxplot.showmeans: True
boxplot.showcaps: True
boxplot.showbox: True
boxplot.showfliers: True
boxplot.meanline: True
# Box (the main body of the boxplot)
boxplot.boxprops.color: red
boxplot.boxprops.linestyle: dotted
# Median Line
boxplot.medianprops.color: red
boxplot.medianprops.linestyle: solid
# Mean Line
boxplot.meanprops.color: yellow
boxplot.meanprops.linestyle: dashed
# Whiskers
boxplot.whiskerprops.color: #ff5c00 # Orange color in hexadecimal
# Fliers (Outliers)
boxplot.flierprops.marker: o
boxplot.flierprops.markeredgecolor: #fdfc60 # Light yellow in hexadecimal
boxplot.flierprops.markersize: 10