douweiluo0600
douweiluo0600
2015-04-02 15:31

在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??

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dsn46282 dsn46282 6年前

    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/'
    
    点赞 评论 复制链接分享