箱形图中的框的面型 [英] Face pattern for boxes in boxplots

查看:96
本文介绍了箱形图中的框的面型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做某种事情(使用matplotlib):

I would like to do something of the sort (using matplotlib):

(来自 R-cran中的带有线,点或类似图形的Colorfill箱线图

我看到了一些有关填充的信息?但是我真的不能在如何使用它上做任何事情。

I saw some info about hatch(ing)? But I really can't make heads or tails on how to use this.

我也发现自己想知道如何更改像boxprop dict的可能属性这样的参数- -在plt.boxplot(...,boxprops = boxpropsdict)中使用。

Also I find myself wondering how can I change parameters like the possible attributes of a boxprop dict -- used in plt.boxplot(..., boxprops=boxpropsdict). Is it possible to just have a list of all the possible attributes for this?

推荐答案

重要的方面是设置 patch_artist = True 调用 boxplot 时。

The important aspect is to set patch_artist=True when calling boxplot.

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()

基本情节示例来自箱线图演示。但是,这些示例都没有设置 patch_artist = True 。如果省略该语句,则会出现此错误:

The basic plot example is taken from the boxplot demo. However, none of those examples set patch_artist=True. If that statement is omitted, you will get this error:


AttributeError: Line2D对象没有属性 set_facecolor

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

boxplot演示2 显示更详细地讲,如何将矩形拟合到箱线图以获得颜色。 此博客指向 patch_artist 。

有关孵化的更多信息,请参见孵化演示。上面的示例产生了此图:

The boxplot demo 2 shows in great detail, how rectangles can be fitted to the boxplot in order to obtain coloring. This blog points to the option of the patch_artist.
For more ideas about hatches, refer to the hatch demo. The example above produces this figure:

这篇关于箱形图中的框的面型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆