Matplotlib: Boxplot outlier color change if keyword sym is used

Seb*_*itz 5 python matplotlib

Applies only to Matplotlib <1.4.0!

I have the strange effect, that the color of the outlier changes, if i change the symbol used to draw them. (Documentation for Boxplot) Seems to me like a bug.

How can i 'reset' the colour to blue for all outlier even if i want to use another symbol than "+"?

Minimal Working Example modeled after official Example:

#!/usr/bin/python

from pylab import *

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

# Left Figure
boxplot(data)

# Right Figure
figure()
boxplot(data, sym='.')
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

Seb*_*itz 2

就像 BrenBarn 和 Joop 正确指出的那样,最简单的方法是用字符指定颜色:boxplot(data, sym='b.')将颜色重置为蓝色或sym='gx'图中的绿色 x。

在这个问题的帮助下,我们能够找到一种方法来使异常值完全可定制。(我想减少异常值的大小)

# insert this after lines '#Right figure', 'figure()'

r = boxplot(data, sym="w") # outlier are computed but not drawn

top_points = r["fliers"][0].get_data()[1]
bottom_points = r["fliers"][2].get_data()[1]
plot(np.ones(len(top_points)), top_points, "x", color="blue", markersize=1)
plot(np.ones(len(bottom_points)), bottom_points, ".", color="blue")
#if you have several boxplots this "np.ones(len(bottom_points))" is the number of plot you want to draw in, so 1s for the first [2,2,2,2,...] for the second ect.
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述