在Web应用程序服务器(php)中使用matplotlib时出现问题
问题描述:
I have a python program that starts with:
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
It gives me error when I try to open it with php. I have googled and apparently if I do this before importing pylab or pyplot:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
Problem should be solved. But the error I get is:
/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
Any idea what's going on??
我有一个python程序,它以: p>
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
code> pre>
当我尝试用php打开它时,它给了我错误。
我用google搜索了 显然,如果我在导入pylab或pyplot之前这样做: p>
导入matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot为plt
code>
问题应该解决。 但我得到的错误是: p>
/usr/lib/pymodules/python2.7/matplotlib/__init__.py:923:UserWarning:这次调用matplotlib.use() 没有影响
因为已经选择了后端;
*之前必须调用
?nmatplotlib.use()* * *首先导入* pylab,matplotlib.pyplot,\或matplotlib.backends
code> pre>
知道发生了什么事吗? p>
div>
答
The default backend is specified in the matplotlibrc
file -- you could try changing it there.
It may also be that whatever environment you are running python in may already import matplotlib and specify the backend as part of the configuration. Also, some post suggest the following line may be needed:
os.environ[ 'MPLCONFIGDIR' ] = '/tmp/'