Python matplotlib - errorbar 无系列值 [英] Python matplotlib - errorbar None values in series

查看:45
本文介绍了Python matplotlib - errorbar 无系列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用误差线绘制一个系列.该系列可能包含 None 值.不使用错误时-绘制的序列没有错误.尝试使用误差线绘图时 - 我收到此错误:

I was trying to plot a series with error bars. The series may contain None values. When not using the errors - the series is plotted with no error. When trying to plot with the error bars - I get this error:

我的代码是:

x = [10.4, 11.12,11.3,None, 10.2,11.3]
y = [0.3, 1.2, 0.7, None, 1.1, 0.4]
y_err = [0.01, 0.04, 0.07, None, 0.01, 0.05] 

plt.plot(x,y, 'o', color='r') # this one works. I get a plot with 5 points. The null point is skipped
plt.errorbar(x,y,yerr=y_err) # this one doesn't work

我得到的错误是:

 TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'

有什么办法可以跳过一系列的空值?

Is there any way to skip the null values in a series?

谢谢!

推荐答案

尝试使用NaN而不是无".

Try using NaN rather than "None".

x = [10.4, 11.12,11.3,float('NaN'), 10.2,11.3]
y = [0.3, 1.2, 0.7, float('NaN'), 1.1, 0.4]
y_err = [0.01, 0.04, 0.07, float('NaN'), 0.01, 0.05] 
plt.plot(x,y, 'o', color='r')
plt.errorbar(x,y,yerr=y_err)

在没有numpy的python中分配变量NaN

这篇关于Python matplotlib - errorbar 无系列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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