箱线图中箱子的面部图案

Face pattern for boxes in boxplots

我想做类似的事情(使用 matplotlib):

(来自 Colorfill boxplot in R-cran with lines, dots, or similar

我看到了一些关于孵化的信息?但是我真的不知道如何使用它。

我也发现自己想知道如何更改参数,例如 boxprop dict 的可能属性——在 plt.boxplot(..., boxprops=boxpropsdict) 中使用。是否可以只列出所有可能的属性?

重要的一点是在调用boxplot时设置patch_artist=True

import numpy as np
import matplotlib.pyplot as plt

# fake up some data
spread= np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low), 0)

# basic plot
bp = plt.boxplot(data, patch_artist=True)

for box in bp['boxes']:
    # change outline color
    box.set(color='red', linewidth=2)
    # change fill color
    box.set(facecolor = 'green' )
    # change hatch
    box.set(hatch = '/')

plt.show()

基本情节示例取自boxplot demo。但是,这些示例中 none 设置为 patch_artist=True。如果省略该语句,您将收到此错误:

AttributeError: 'Line2D' object has no attribute 'set_facecolor'

boxplot demo 2 shows in great detail, how rectangles can be fitted to the boxplot in order to obtain coloring. This blog指向patch_artist的选项。
有关舱口的更多想法,请参阅 hatch demo。上面的例子产生了这个数字: