Matplotlib 不在 virtualenv 中显示图形 [英] Matplotlib doesn't display graph in virtualenv
问题描述
我在virtualenv中安装了pip matplotlib,并且试图绘制一个简单的图形.我使用Eclipse和PyDev.当我从 Eclipse 运行脚本时,它根本不显示任何图形.我已经尝试了其他问题(例如添加plt.ion())中提出的建议,但这也不起作用.我也曾在控制台中尝试过相同的代码,再也没有尝试过.我的配置有问题吗?如果是这样,我该如何解决?
I have pip installed matplotlib in my virtualenv and I am trying to plot a simple graph. I use Eclipse and PyDev. When I run the script from Eclipse it doesn't display any graph at all. I have tried the suggestions proposed in other questions such as adding plt.ion() but that doesn't work either. I have also tried the same code in the console and again nothing. Is this a problem with my configuration? If so how can I fix it?
失败的代码是:
import matplotlib.pyplot as plt
radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724]
plt.plot(radius, area)
plt.show()
代码不是问题.在virtualenv中,它工作得很好.问题是当我在virtualenv中使用它时.问题在某种程度上与我的配置有关.而且只是为了清除问题,我不会收到任何错误消息.只是窗口不会出现.
The code is not the problem. It works just fine out of virtualenv. The problem is when I use it in virtualenv. The problem is somehow related to my configuration. And just to clear things up I DON'T GET ANY error messages. It's just that the window wouldn't show up.
谢谢
推荐答案
你的代码可以在我的 OSX 10.7 和 Python 2.7 上的 virtualenv 中工作:
Your code works inside my virtualenv on OSX 10.7 with Python 2.7:
您在virtualenv中使用什么版本的Python?我的猜测是您没有安装 matplotlib 依赖项,或者您未正确安装已安装的依赖项.在 Python 2.7 上,这是我为安装 matplotlib 所做的.您可以在新的virtualenv中尝试这些步骤,看看它是否对您有用吗?
What version of Python are you using inside your virtualenv? My guess is that either you have not installed a matplotlib dependency or your installation of an installed dependency was not properly performed. On Python 2.7 here is what I did to install matplotlib. Can you try these steps in a new virtualenv and see if it works for you?
pip install numpy
pip install scipy
easy_install matplotlib
这篇关于Matplotlib 不在 virtualenv 中显示图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!