2014-02-27 21 views
7

我使用Python 2.7.6 32位與Matplotlib 1.3.1。
當我在這個例子中使用默認後端,像,圖所示:Matplotlib:WebAgg後端不顯示任何數字

import matplotlib.pyplot as plt 
plt.plot(range(10)) 
plt.show() 


當我嘗試自動使用WebAgg中,MPL頁面加載,但沒有任何數字:

import matplotlib 
matplotlib.use('webagg') 
import matplotlib.pyplot as plt 
plt.plot(range(10)) 
plt.show() 


我在Windows和Ubuntu上使用Firefox,Chrome和IE測試了這段代碼,沒有任何成功...
有人可以幫忙嗎?提前致謝!

+1

您的代碼工作正常,我。該圖形在瀏覽器窗口中彈出。你有其他的錯誤嗎? –

+1

我的建議是嘗試重新安裝Python和matplotlib。這通常會很難解決你的問題。 –

+0

使用VirtualBox,我嘗試了Ubuntu 12.10(隨附Python 2.7.3)的全新安裝,然後安裝了NumPy,Matplotlib及其依賴項。但是,WebAgg瀏覽器窗口仍然只顯示「圖1」鏈接,沒有任何數字。點擊鏈接也沒有結果。 – alissonmuller

回答

1

很多搜​​索和測試後,我結束了使用PIP卸載Matplotlib,然後重新安裝(使用--upgrade命令,只是要確定):

pip uninstall matplotlib 
pip install matplotlib --upgrade 

和它的工作!現在我可以在瀏覽器窗口中看到WebAgg圖! 也許我沒有安裝正確Matplotlib ...

感謝您的建議!

1

更新到最新的開發版本,Matplotlib-1.4.x的。使用virtualenv安裝

$ pip install -e [email protected]:matplotlib/matplotlib.git 

然後OP的命令可以在所有平臺上運行。還有一個新的embedded webagg example in the matplotlib master branch on GitHub適用於我所有的系統(Windows-7x64,Ubuntu-14.14和Xubuntu-14.14)。

使用OP的命令與Matplotlib-1.3.1,我得到的這取決於不同的結果在哪個平臺上我使用。在一臺機器(Ubuntu的14.14),我是能夠顯示數字,如果我用sudo執行OP的命令:

$ sudo python 
>>> import matplotlib 
>>> matplotlib.use('webagg') 
>>> import matplotlib.pyplot as plt 
>>> plt.plot(range(10)) 
>>> plt.show() 

這適用於的virtualenv和matplotlib的Ubuntu發行版本。

雖然的VMware Player虛擬機(Xubuntu上-14.14託管在Windows的7x64)對我是能夠顯示利用OP的命令圖中沒有sudo。在第三臺(Windows-7x64)機器上,我仍然無法使用OP的命令獲取數字,無論是否具有管理員權限。我也將matplotlib.rcParams['webagg.port']更改爲8080和8000,但這也沒有奏效。

在Ubuntu-14.14使用matplotlib從分佈的存儲庫安裝,您將看到下面的回溯:

File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_webagg.py", line 381, in get 
'matplotlib.png'), 'rb') as fd: 
IOError: [Errno 2] No such file or directory: '/usr/lib/pymodules/python2.7/matplotlib/mpl-data/images/matplotlib.png' 

它無關,爲什麼圖像不顯示;此錯誤只出現在其中mpl-data文件夾不在matplotlib.backends.backend_webagg預期的位置,但實際上位於/usr/share/matplotlib/的Linux機器上。具體來說,backend_webagg正在尋找它用作web瀏覽器選項卡圖標的文件matplotlib.png,實際上即使Tornado沒有找到該文件,它仍然會提供該頁面,但不幸的是它仍然會發出此錯誤。

如果您使用virtualenv,您將看不到favicon錯誤。

使用Matplotlib-1.3。1在Ubuntu-14.14和Windows-7x64機器上沒有sudo我收到了@allisonmuller在上面評論中看到的相同的「圖1」鏈接問題。

0

只是增加了馬克Mikovski的答案,我發現,如果添加一個符號鏈接如下

CD /usr/lib/pymodules/python2.7/matplotlib/

LN -s在/ usr /分享/ matplotlib/MPL-數據MPL-數據

這似乎是解決問題