问题
I have two lists of numbers which I'm using matplotlib to graph in Python. However if one of the lists begins with the value of nan, matplotlib will not graph any of the 15k+ points I have. However if there is a nan value somewhere in the list after the first value, it simply skips it and graphs the other points fine. I'm curious how to work around this without changing the first nan value.
回答1:
you can use the numpy.isnan
function to mask your list:
a=np.array([np.nan,1,2,3,4,np.nan])
mask=~np.isnan(a)
maskedA=a[mask]
#... Plot maskedA here, continue working with a as you normally would.
I'm not sure why you want to keep the first nan value -- what do you want matplotlib to do with it other than simply ignore it? i.e. what do you mean by this statement -- "I'm curious how to work around this without changing the first nan value."
来源:https://stackoverflow.com/questions/10939391/matplotlib-issues-when-nan-first-in-list