简体   繁体   中英

Matplotlib Errorbar behaviour with NaNs

I have some data y plotted against x with asymmetric error bars yerr ( =[up, down] ). The data, y, contains some np.nan values at the end and likewise for yerr. However, when I plot the data using matplotlib's errorbar function, it gets this weird marker behaviour:

在x轴上看到30左右

What could cause this? I ran a few checks and the nan values line up, meaning that they shouldn't be plotted at all!

Heres the function:

axis.errorbar(profile.R, profile.M, yerr=profile.MW, fmt='b.')

axis.set_ylim(axis.get_ylim()[::-1])

and here's some pictures: after re-phrase: axis.errorbar(profile.R, profile.M, yerr=(profile.MW[0], profile.MW[1]), fmt='b.') , it still produces the same plot after re-phrase: axis.errorbar(profile.R, profile.M, yerr=(profile.MW[1], profile.MW[1]), fmt='b.') 仅带有向上的错误栏

I've also downgraded matplotlib and it still doesn't work!

But when I take the values out of their np.arrays for the last 8 elements by hand ( axis.errorbar([32.9592, 34.60716, 36.33696, 38.15418, 40.06254, 42.06576, 44.16756, 46.37724],[np.nan, 28.18328608, 27.41428602, np.nan, 27.30407038, np.nan, np.nan, np.nan], yerr=[[np.nan, 1.16532339, 0.73753135, np.nan, 0.68722997, np.nan, np.nan, np.nan], [np.nan, 1.16532339, 0.73753135, np.nan, 0.68722997, np.nan, np.nan, np.nan]]) )

现在可以使用WTF吗? it works!! WTF!

Any ideas?

Thanks

Shouldn't be. Show us some of your data and code. Version related? I don't think so, I am on matplotlib 1.3.1

>>> import matplotlib.pyplot as plt
>>> from numpy import *
>>> x=arange(10)*1.
>>> y=random.randint(0,20,size=10)*1.
>>> plt.plot(x, y, 'o-')
>>> y[6]=np.nan
>>> y[8]=np.nan
>>> e=random.random(size=10)
>>> e[6]=np.nan
>>> e[8]=np.nan
>>> e1=random.random(size=10)
>>> e1[8]=np.nan
>>> e1[6]=np.nan
>>> e0=vstack((e,e1))
>>> plt.errorbar(x,y,yerr=e)
<Container object of 3 artists>
>>> x
array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.])
>>> y
array([ 12.,   7.,   2.,   4.,  16.,   4.,  nan,   5.,  nan,  14.])
>>> e
array([ 0.55292182,  0.18636933,  0.4564491 ,  0.74029   ,  0.54939223,
        0.98015167,         nan,  0.08164338,         nan,  0.1865567 ])
>>> e1
array([ 0.31619386,  0.06603335,  0.63795806,  0.70372424,  0.8639665 ,
        0.01439499,         nan,  0.73742553,         nan,  0.06838048])

在此处输入图片说明

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM