Opened 9 years ago

Closed 8 years ago

#26 closed defect (fixed)

matplotlib backend already chosen due to import order sensitivity

Reported by: flip Owned by:
Priority: major Milestone:
Component: common Version:
Keywords: Cc:


Each of our apps at one time or another has run into this problem. Our
use of matplotlib is sensitive to import order. Specifically, our plot_panel
code (and wxmpl when we were still using that) call matplotlib.use().
That call can print an ugly warning to stdout if a backend has been
implicitly chosen by an earlier import of pylab, matplotlib.pyplot,
or matplotlib.backends.

The specific message:

site-packages/matplotlib/ UserWarning:  This call to matplotlib.use() has no effect
because the the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

  if warn: warnings.warn(_use_error_msg)

An easy (but perhaps not the best) fix is to add this line as the first
Vespa import in each app's

import vespa.common.wx.plot_panel

That ensures that the call to matplotlib.use() happens before any of our
other modules can do anything that implies a matplotlib backend choice.

Change History (2)

comment:1 Changed 9 years ago by flip

Fixed by (a) forcing the import of plot_panel in (as suggsted) and (b) making calls to matplotlib.use() conditional based on whether or not the correct backend is already chosen (r1986).

I'm leaving this open because this bug has been hard to squash and I'm not confident we've gotten it this time.

comment:2 Changed 8 years ago by flip

  • Resolution set to fixed
  • Status changed from new to closed

We haven't seen this in over a year so I'm closing it now (which means it will probably reappear this afternoon...)

Note: See TracTickets for help on using tickets.