matplotlib在nan列表中时首先发布 [英] matplotlib issues when nan first in list

查看:137
本文介绍了matplotlib在nan列表中时首先发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个使用matplotlib在Python中进行图形化的数字列表。但是,如果其中一个列表以nan的值开始,那么matplotlib将不会绘制我拥有的任何15k +点。但是,如果在第一个值之后的列表中某处存在一个nan值,它会简单地跳过它,并将其他点正确地绘制成图。我很好奇如何解决这个问题而不改变第一个nan值。

> numpy.isnan 函数掩盖你的列表:

  a = np.array([np。 nan,1,2,3,4,np.nan])
mask =〜np.isnan(a)
maskedA = a [掩码]

#...在这里绘制蒙面人物,继续像往常一样使用a。

我不确定为什么要保留第一个nan值 - 你想要matplotlib除了简单忽略它之外呢?即你的意思是什么 - 我很好奇如何在不改变第一个nan值的情况下解决这个问题。


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.

解决方案

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."

这篇关于matplotlib在nan列表中时首先发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆