douweiluo0600 2015-04-02 15:31
浏览 200
已采纳

在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 2015-04-02 16:21
    关注

    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/'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办