Canvas freezes on matplotlib import

If directly or indirectly through any other package, matplotlib is imported, then the output plot is shown, but freezes, i.e. one can not zoom axis etc. Unfortunately some not so well designed 3rd party mathematical packages in python have some kind of visualization deep in their code, which imports matplotlib. So even if I don’t need matplotlib, it gets imported automatically.

To reproduce the error, I just took the small sin(x)/x example code on the PyROOT main page


at the beginning, it freezes. Commented out, it works.

Appreciate any ideas…

p.s. Using Python 3.4.5 +readline, root v. 6.06/08 +python34 from Macports on OSX 10.11.6 El Capitan

Two graphic interfaces computing for the main loop is probably the source of the problem. I’ll try to reproduce it and see whether there is a workaround.


AFAIK, a lot of folks are happily mixing mathplotlib and PyROOT. PyROOT can use either a separate progress thread or the input hook. See whether it makes a difference:import ROOT ROOT.PyConfig.StartGuiThread = 'inputhook'for input hook, or:import ROOT ROOT.PyConfig.StartGuiThread = Truefor progress thread.


Sorry for hijacking this thread, but I’m seeing this with ROOT 6.10/00 on MacOS Sierra.

I’ve tried

>>> import ROOT
>>> ROOT.PyConfig.StartGuiThread = 'inputhook'
>>> import matplotlib.pyplot as plt
>>> c = ROOT.TCanvas()


>>> import ROOT
>>> ROOT.PyConfig.StartGuiThread = True
>>> import matplotlib.pyplot as plt
>>> c = ROOT.TCanvas()

And in both cases the TCanvas is “frozen” until I hit enter in the python prompt. Did I interpret your instructions wrong?


It seems that you are using python shell itself. I can also reproduce the behaviour you mention. Both freeze. The same happens if you take a tutorial example form ROOT distribution, e.g., add a single line above it:

import matplotlib.pyplot as plt

then try to load it within python3 shell:


This also freezes.

But it turns out that all the problems are gone using iPython shell instead of python shell itself. There both of your codes will not freeze and also running:


also won’t freeze.

This means that my problem in the original post seems to have been solved as well.

btw. I am using root6 @6.10.00_2+cocoa+cxx14+cxx17+gcc6+graphviz+gsl+http+minuit2+opengl+python34+roofit+soversion+ssl+tmva+xml and python34 @3.4.6_1+readline on OSX El Capitan.