Pierre GM wrote:
> On Wednesday 29 August 2007 10:02:14 John Morgan wrote:
>> I have some data, which I'd like to plot using matplotlib. Some of the data
>> has been flagged by some other software, and I have a boolean array, the
>> same shape as my original data which tells me which data has been flagged
If you are only plotting symbols, you can either use masked arrays, as
Pierre suggests, or simply plot the selected points:
plot(x[b], y[b], '.', x[~b], y[~b], 'x')
where x, y, and b are all numpy arrays of the same shape.
>> I'm sure I can get this approach to work but I thought I'd ask if there's
>> there a more elegant way to achieve the same aim.
> two words: masked arrays.
In the matplotlib distribution, see examples/masked_demo.py
>>>> import numpy
>>>> flagged = numpy.ma(initial_array, mask=boolean_array)
> That will take care of the unmasked data.
> For the masked values, just revert the mask.