Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib doesn't display graph in virtualenv

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?

The failing code is:

    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()

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.

Thanks

like image 982
George Eracleous Avatar asked Jan 29 '12 16:01

George Eracleous


2 Answers

Your code works inside my virtualenv on OSX 10.7 with Python 2.7:

enter image description here

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
like image 155
drbunsen Avatar answered Sep 19 '22 06:09

drbunsen


I had the same issue, and installing matplotlib using easy_install instead of pip did not solve it. In the end, I found out that the problem was simply that matplotlib could not find any backend for plotting.

I solved it by doing the following (I am using Debian wheezy):

pip uninstall matplotlib
sudo apt-get install tcl-dev tk-dev
pip install matplotlib
like image 28
Wookai Avatar answered Sep 19 '22 06:09

Wookai