Masked Arrays

How can I set only unclosed MaskedArray values? I am sure this will happen automatically using boxplot(ma), but it does not seem that boxplot is a maskable array.

+5
source share
1 answer

I think you're right - plt.boxplotignores the mask if a masked array is sent. It looks like you will have to provide boxplotadditional help by sending her only values ​​that are not masked. Since each row of the array can have a different number of unoiled values, you cannot use the numpy array. You will need to form a sequence of Python vectors:

z = [[y for y in row if y] for row in x.T]

For instance:

import matplotlib.pyplot as plt
import numpy as np

fig=plt.figure()

N=20
M=10

x = np.random.random((M,N))
mask=np.random.random_integers(0,1,N*M).reshape((M,N))
x = np.ma.array(x,mask=mask)
ax1=fig.add_subplot(2,1,1)
ax1.boxplot(x)

z = [[y for y in row if y] for row in x.T]
ax2=fig.add_subplot(2,1,2)
ax2.boxplot(z)
plt.show()

enter image description here

, x ( ), , .

+6

All Articles