2015-04-02 40 views
1

使用maptlotlib我有一個開頭python程序:麻煩Web應用程序服務器(PHP)

from optparse import OptionParser 
import math 
#import wx 
import os 
import numpy as np 
import matplotlib.pyplot as plt 
from pylab import * 
from numpy import * 
import scipy as scipy 
from scipy import * 
from scipy import constants 
import scipy.signal as signal 
import matplotlib.pyplot as plt 

它給了我的錯誤,當我嘗試用PHP打開它。 我用Google搜索,顯然,如果我進口pylab或pyplot之前:

import matplotlib 
matplotlib.use('Agg') 
import matplotlib.pyplot as plt 

問題應該得到解決。但我得到的錯誤是:

/usr/lib/pymodules/python2.7/matplotlib/__init__.py:923:  UserWarning: This call to matplotlib.use() has no effect 
because the the backend has already been chosen; 
matplotlib.use() must be called *before* pylab, matplotlib.pyplot, 
or matplotlib.backends is imported for the first time 

任何想法發生了什麼事?

回答

0

matplotlibrc文件中指定了默認後端 - 您可以嘗試在此處更改它。

也可能是,無論您在python中運行的環境是否已經導入matplotlib,並將後端指定爲配置的一部分。此外,some後建議可能需要以下行:

os.environ[ 'MPLCONFIGDIR' ] = '/tmp/' 
+0

你如何建議我改變後端?我應該怎樣改變它? – Jack 2015-04-02 18:03:09

+0

嘗試'locate',通常可以在etc中找到示例matplotlibrc,也許在.config/matplotlib/matplotlibrc中默認文件。同樣在http://matplotlib.org/users/customizing.html。 matplotlib將優先在本地目錄中使用'.matplotlibrc'的版本來定義後端。如果python的建議是'Agg' for php,請嘗試更改爲此。但是,聽起來像後端可能會在從PHP調用時在其他地方指定。 http://texnological.blogspot.co.uk/2013/01/how-to-execute-python-matplolib-pylab.html中的其他帖子無法幫助嗎? – 2015-04-02 21:40:58