簡體   English   中英

Matplotlib錯誤欄行為與NaN

[英]Matplotlib Errorbar behaviour with NaNs

我有一些數據y相對於x具有不對稱誤差線yerr( =[up, down] )。 數據y的末尾包含一些np.nan值,對於yerr同樣如此。 但是,當我使用matplotlib的errorbar函數繪制數據時,它會得到以下奇怪的標記行為:

在x軸上看到30左右

是什么原因造成的? 我進行了幾項檢查,然后將nan值對齊,這意味着根本不應該繪制它們!

繼承函數:

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

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

這是一些圖片:重新措辭后: axis.errorbar(profile.R, profile.M, yerr=(profile.MW[0], profile.MW[1]), fmt='b.') ,它仍然axis.errorbar(profile.R, profile.M, yerr=(profile.MW[1], profile.MW[1]), fmt='b.')后產生相同的圖: axis.errorbar(profile.R, profile.M, yerr=(profile.MW[1], profile.MW[1]), fmt='b.') 僅帶有向上的錯誤欄

我還對matplotlib進行了降級,但仍然無法正常工作!

但是當我手動從最后8個元素的np.array中取出值時( 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嗎? 有用!! WTF!

有任何想法嗎?

謝謝

不應該。 向我們展示您的一些數據和代碼。 版本相關嗎? 我不這么認為,我在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])

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM