3

I have a very similar question to this one: matplotlib does not show my drawings although I call pyplot.show()

I am using: Ubuntu 12.04; Python 3.4.1; Pycharm 3.4.1

So, I run the following code in pyCharm using 3.4.1 interpreter and plot doesn't appear:

import matplotlib.pyplot as p 
p.plot(range(20), range(20))
p.show()

Then I thought it could be something with pycharm, therefore I have tried the same in the terminal. However, plot didn't appear too.

However, since Ubuntu is with built-in Python 2.7, I have tried the same on terminal, then on pycharm and plot did appear.

I have found out that backend in matplotlibrc file should be changed. I googled, that qt4agg backend should be used. After changing it and trying to import matplotlib.pyplot I get the following

import matplotlib.pyplot as p
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py", line 98, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/__init__.py", line 28, in pylab_setup
globals(),locals(),[backend_name],0)
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_qt4agg.py", line 13, in <module>
from .backend_qt4 import QtCore, QtGui, FigureManagerQT, FigureCanvasQT,\
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_qt4.py", line 25, in <module>
from .qt4_compat import QtCore, QtGui, _getSaveFileName, __version__
File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/qt4_compat.py", line 36, in <module>
import sip
ImportError: No module named 'sip'

Therefore, I installed sip using

 sudo apt-get install python3-sip

and the same error appears.

I am trying to find out whats wrong with SIP. However, I am kinda confused, any help would be appreciated. Thanks

Community
  • 1
  • 1
adomasb
  • 496
  • 4
  • 14
  • Hi I'm new to Python but I've found that by running iptest has helped me identify components I need to install. I've succesffully install ipython and notebook. I'm using Python 2.7 btw. – Roobie Jul 02 '14 at 13:55
  • how did you set the backend? gtk backend should work. – Padraic Cunningham Jul 02 '14 at 14:07
  • I went to `/usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data` and changed matplotlibrc file `backend : gtk`. Now I get other error: `ImportError: No module named 'gobject'` which I have installed via `sudo apt-get install python-gobject`. – adomasb Jul 03 '14 at 07:57
  • I reproduced another example. If I save my graph, it works. Code I used from matplotlib documentation: `from pylab import * t = arange(0.0, 2.0, 0.01) s = sin(2*pi*t) plot(t, s) xlabel('time (s)') ylabel('voltage (mV)') title('About as simple as it gets, folks') grid(True) savefig("test.png") show()` Therefore, this works. However, trying to run code without save `savefig()` it does not. – adomasb Jul 07 '14 at 07:04

1 Answers1

1

Alright, so after a lot of effort, I finally managed to do it.

Firstly, I had probably, three or four different python versions in my computer: 2.7 as ubuntu default, 3.2, 3.4.0 and 3.4.1. Each of them had different versions of matplotlib (majority 1.3.1). So, firstly I cleaned up useless python versions (3.2, 3.4).

Secondly, I removed all available matplotlib directories. I used matplotlib documentation to determine which folders should be removed to fully remove it. (http://matplotlib.org/contents.html)

After that, I cloned newest matplotlib version from git (http://matplotlib.org/faq/installing_faq.html#install-from-git) and installed it. And this point matplotlib version is 1.4. Then I tried to reproduce my first example again and it worked. No backend was changed.

Thus, clean removal and newest version should do the trick.

adomasb
  • 496
  • 4
  • 14