2014-10-04 96 views
1

我使用python 3.4.1,matplotlib 1.4,ipython 2.3筆記本,Arch Linux。fill_between沒有統一填充

我試圖通過一條線將平面劃分爲兩部分,例如兩個分類區域,其中一個區域具有一個值,另一個區域具有其他值。我對區間[-1,1] x [-1,1]中的區域感興趣。

這裏是一切正常的例子:

import numpy as np 
import matplotlib.pyplot as plt 
a, b = (2.5711100440212684, -0.87718711444141584) 
x = np.arange(-1, 1, 0.001) 
y1 = a*x + b 
y2 = -1 
y3 = 1 
plt.fill_between(x, y1, y2, where=y1>y2, facecolor='green', interpolate=True) 
plt.fill_between(x, y1, y3, where=y1<y3, facecolor='yellow', interpolate=True) 
plt.axis([-1, 1, -1, 1]) 

此代碼給了我一張照片,因爲我認爲它應該: enter image description here

在另一方面,如果我改變的斜坡位,這裏就是我得到:

import numpy as np 
import matplotlib.pyplot as plt 
a, b = (4.5711100440212684, -0.87718711444141584) 
x = np.arange(-1, 1, 0.001) 
y1 = a*x + b 
y2 = -1 
y3 = 1 
plt.fill_between(x, y1, y2, where=y1>y2, facecolor='green', interpolate=True) 
plt.fill_between(x, y1, y3, where=y1<y3, facecolor='yellow', interpolate=True) 
plt.axis([-1, 1, -1, 1]) 

enter image description here

有可能我錯過了一些東西。如果有人看到這個錯誤,請告訴我。

編輯:哦,是的,綠色填充似乎適用於所有的斜率值。

回答

1

它適合我。使用Matplotlib每晚構建,Ubuntu 14.04,Python 3.4,,但從控制檯運行它。你也嘗試過嗎?

enter image description here

+0

我現在做了,我仍然得到這個。這似乎是某種錯誤。你可以檢查你的matplotlib版本嗎?這可能是matplotlib 1.4.0的錯誤。 – enedene 2014-10-04 16:27:46

+0

1.5.x和構建是:https://launchpad.net/~takluyver/+archive/ubuntu/matplotlib-daily – tobias47n9e 2014-10-04 16:30:44

+0

好的,謝謝,它一定是一個bug。我會upvote並接受你的答案。 – enedene 2014-10-04 16:32:54