So I have some data
import pyfits
import matplotlib.pyplot
a = pyfits.getdata('data.fits')
x = a['time']
y = a['flux']
I had a issue with some data where my arrays contained NaN values. To get rid of them, I did the following:
x = x[numpy.logical_not(numpy.isnan(x))]
y = y[numpy.logical_not(numpy.isnan(y))]
Which removes all NaN values from the arrays x
and y
. The problem is that x
and y
did not contain the same amount of NaN values.
so:
len(y) = 4275
whereas:
len(x) = 4313
I'd like to be able to do this:
pyplot.plot(x,y)
but there is a problem with trying to plot arrays of different dimensions. Is there a way that I can do this?
You can zip the the two arrays, and discard any point (x, y)
where either x
or y
is NaN
(I think this makes most sense). Now I'm not familiar with numpy or whether it provides a short way to do this, you might need to implement it yourself.
How are you getting your data plots? I would assume on import you would have x or y be 0 such that each x has an appropriate y?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.