Matplotlib freezes on mac osx and no graph is displayed
I am using the Mac Yosemite and Anaconda distribution for Python 3.4. Whenever I do
import matplotlib.pyplot as plt
...
plt.semilogy(x, y)
plt.show()
an empty window appears in a hanging state.
I saw a similar post: Matplotlib does not display on Mac OSX , which is the recommended way to use
sudo port install py25-matplotlib +cairo+gtk2
sudo port install py26-matplotlib +cairo+gtk2
Since I am using python 3.4 I have tried
sudo port install py34-matplotlib +cairo+gtk2
The installation went fine, but when I tried import matplotlib
on the Python console inside PyCharm I got the following error:
Backend GTKCairo is interactive backend. Turning interactive mode on.
Failed to enable GUI event loop integration for 'gtk'
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_console_utils.py", line 498, in do_enable_gui
enable_gui(guiname)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_ipython/inputhook.py", line 479, in enable_gui
return gui_hook(app)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_ipython/inputhook.py", line 227, in enable_gtk
from pydev_ipython.inputhookgtk import create_inputhook_gtk
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_ipython/inputhookgtk.py", line 19, in <module>
import gtk, gobject
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named 'gtk'
-
What could be the problem?
-
I could not find a module
gtk
in PyCharm, but foundPyGTK
,PyGTKCodeBuffer
,PyGTKImageView
etc. Is there any site for the modulegtk
?
* EDIT *
I solved this problem by adding Interactive : True
to the file matplotlibrc
.
I got it by following the instructions in this blog post .
Briefly replace:
import matplotlib.pyplot as plt
with the following:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
and the graph window will open (for me it opened in the background, hidden behind my IDE, so at first I thought nothing happened)
You write in this post: ply.show ()
The correct form is plt.show (). This is your mistake? or you are only writing incorrectly in this post
Why are you using the port with anaconda?
From the conda environment (i.e. after typing from the command line source activate my_env
, where my_env is the name of your environment):
condo update conda
conda install matplotlib
conda install pyqt