plotting only if not zero?

Hi

It's certainly no important problem and there are ways to work around it, but I was wondering whether there is a way to do it directly using matplotlib.
My 'problem' is as follows: My detector does not detect at all times; in case nothing is detected a 0 is written in the data-file. So what I end up with are data like [0,0,1000,1001,999,0,1000 ...], which - of course - looks a bit odd, when plotted. (The 0s are meaningless.) Is it possible to plot only values unequal to zero? Or is there any other way to 'mask' data which should be skipped for the plot?

Thanks a lot in advance,
Christian

Hi

It's certainly no important problem and there are ways to work around
it, but I was wondering whether there is a way to do it directly using
matplotlib.
My 'problem' is as follows: My detector does not detect at all times;
in case nothing is detected a 0 is written in the data-file. So what I
end up with are data like [0,0,1000,1001,999,0,1000 ...], which - of
course - looks a bit odd, when plotted. (The 0s are meaningless.) Is it
possible to plot only values unequal to zero?

What about using compress before plotting:

In [1]: from Numeric import *
In [2]: x=arange(10)
In [3]: x
Out[3]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
In [4]: xred=compress(x>0,x)
In [5]: xred
Out[5]: array([1, 2, 3, 4, 5, 6, 7, 8, 9])

Or is there any other way
to 'mask' data which should be skipped for the plot?

There are also masked arrays in matplotlib, maybe
some else has a simple example.

Best,

Arnd

ยทยทยท

On Tue, 6 Sep 2005, Christian Meesters wrote:

Thanks, Arnd & Christian.

Combining your answers and the example on masked plots brought me to this solution (pseudo code):

y_values = M.array(y_values)
y_values = M.masked_where(y_values < threshold , y_values) #mask values below a certain threshold

pylab.plot(x_values, y_values,'k-')
a.set_xlim(x_values[0], x_values[-1]) #for otherwise the range of x_values gets truncated

Well, the solution IS easy and pretty straightforward, but I didn't realise that for a while ...

Cheers,
Christian