matplotlib - 在 matplotlib 中仅对一些带有箱线图的框进行样式化
解决方案
已经对 seaborn 箱线图提出了同样的问题。对于 matplotlib 箱线图,这更容易,因为boxplot
直接返回相关艺术家的字典,请参阅boxplot
文档。
这意味着如果bplot = ax.boxplot(..)
是您的箱线图,您可以通过 访问这些框bplot['boxes']
,选择其中一个并将其线型设置为您想要的。例如
bplot['boxes'][2].set_linestyle("-.")
import matplotlib.pyplot as plt
import numpy as np
# Random test data
np.random.seed(19680801)
all_data = [np.random.normal(0, std, size=100) for std in range(1, 4)]
labels = ['x1', 'x2', 'x3']
fig, ax = plt.subplots()
# notch shape box plot
bplot = ax.boxplot(all_data, vert=True, patch_artist=True, labels=labels)
# Loop through boxes and colorize them individually
colors = ['pink', 'lightblue', 'lightgreen']
for patch, color in zip(bplot['boxes'], colors):
patch.set_facecolor(color)
# Make the third box dotted
bplot['boxes'][2].set_linestyle("-.")
plt.show()
推荐阅读
- mysql - 如何在 Laravel 7 的刀片视图中动态显示数据库中的项目总数
- ios - 像 UIActivityIndicatorview 一样为 UIBezierPath 六边形设置动画
- grafana - grafana,sqlite,非时间系列,如何订购分类数据?
- go-gorm - 为什么在使用原始 sql 的 exec 使用 go-gorm 时,表名在 linux 中自动更改为大写
- highcharts - pointInterval 不适用于折线图中的日期范围
- mysql - 在 MySQL 中加入三个表,同时将具有相同日期的记录放在同一行上
- javascript - FancyTree:如何展开所有嵌套/后续节点?不仅是当前节点
- r - 是否可以允许用户在编织后直接从 PDF 运行 R Studio 中的特定代码块?
- algorithm - 在桶排序中使用快速排序时,桶排序是否稳定?
- php - 处理特定列上的唯一键错误