Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-7909

Simultaneous use of matplotlib and ROOT breaks ROOT canvas



    • Bug
    • Status: Open (View Workflow)
    • High
    • Resolution: Unresolved
    • 6.06/00, 5.34/34, master
    • None
    • GUI, PyROOT
    • None


      Summary: When ROOT and matplotlib's pyplot are used in a shared python session, the GUI features of ROOT's canvas window are broken.

      This is best explained using an example: In a (fresh) python session executing

      >>> import ROOT
      >>> c = ROOT.TCanvas()

      will create a new canvas and open its window. This window has a menu bar (Items: File, Edit, View, Options, Tools), the user can click the menu items and drop-down menus open.

      Executing the following code

      >>> import ROOT
      >>> import matplotlib.pyplot
      >>> c = ROOT.TCanvas()

      will also open a canvas, however, the menu items remain unresponsive. Clicking on a menu item does not result in a drop-down menu being shown.

      Additional remarks:

      • The order of the imports does not matter. If the canvas is created prior to import pyplot, it will remain responsive up to the point when pyplot is imported.
      • The plotting functionality of the canvas remains functional: plotted histograms show, the axes can be changed (using the accessor functions rather than the GUI).
      • Sometimes, the down-down menu will show for a split-second when closing the python interpreter.

      I did some further investigation, the issue seems to be related to conflicts between the UI backends / handlers of matplotlib and ROOT.

      Important: The issue can be worked-around by changing the backend of matplotlib:

      >>> import ROOT
      >>> import matplotlib
      >>> matplotlib.use('Agg')
      >>> import matplotlib.pyplot
      >>> c = ROOT.TCanvas()

      will result in a properly working ROOT canvas, however, we are now stuck with the non-interactive, most basic matplotlib backend.




            etejedor Enric Tejedor Saavedra
            fawilk Fabian Wilk (Inactive)
            1 Vote for this issue
            4 Start watching this issue