Matplotlib: color change in the Boxplot window when using the sym keyword

Applies only to Matplotlib <1.4.0!

I have a strange effect that the color of the variability changes if I change the character used to draw them. ( Documentation for Boxplot ) It seems to me like a mistake.

How can I “reset” the color blue for all outlier, even if I want to use a different character than “+”?

The minimum working example modeled after the 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='.')

enter image description here

+4
source share
4 answers

BrenBarn Joop, : boxplot(data, sym='b.') reset sym='gx' x .

outlier . ( outlier)

# 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.

enter image description here

+1

. , . boxplot(data, sym='b.') (b ). , , , .

+1

boxplot sym:

*sym* : [ default 'b+' ]  # blue +

+, , . , , . , , .

, :

boxplot(data, sym='+')
boxplot(data, sym='.')

, , -, ( , ). sym = 'b +' sym = 'b.'

+1

, , , , cal plot (. doplot, boxplot). sym, , , axes.

1.4.0 ( , !) boxplot . ( ​​ ) , .

+1
source

All Articles