SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: John M. <mo...@gm...> - 2007年08月29日 14:02:24
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.
What I'd like to do is plot the unflagged data as a single pixels ',' and
flagged data as crosses 'x'.
At the moment I'm plotting all of the data as single pixels, and then
replotting everything as crosses, setting the unflagged data to some
negative number and setting the axes to hide them away off the bottom of the
graph, however this approach is a bit of a pain as you often end up with the
crosses showing up on the bottom of the graph etc.
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.
Many thanks in advance,
John Morgan
From: Pierre GM <pgm...@gm...> - 2007年08月29日 15:50:10
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
> .... 
> 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.
>>>import numpy
>>>flagged = numpy.ma(initial_array, mask=boolean_array)
>>>plot(flagged)
That will take care of the unmasked data.
For the masked values, just revert the mask.
From: Eric F. <ef...@ha...> - 2007年08月29日 16:49:04
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
John,
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)
 numpy.ma.array(...)
>>>> plot(flagged)
> 
> That will take care of the unmasked data.
> For the masked values, just revert the mask.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /