matplotlib issues when nan first in list

主宰稳场 提交于 2019-12-10 22:17:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!