Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matplotlib 2.1.0, backend macosx: need _BackendMac, got FigureManagerMac #9345

Closed
denis-bz opened this issue Oct 10, 2017 · 10 comments

Comments

Projects
None yet
7 participants
@denis-bz
Copy link

commented Oct 10, 2017

Bug report

Bug summary

matplotlib 2.1.0 from ipython with backend macosx ->
need _BackendMac, got FigureManagerMac

Code for reproduction

# Paste your code here
#
#
import sys
import matplotlib as mpl
import matplotlib.pyplot as pl

print "matplotlib.__version__ :", mpl.__version__
print "pl.rcParams['backend'] :", pl.rcParams["backend"]
print "sys.version :", sys.version
    # -> /Library/Frameworks/Python.framework/Versions/2.7/bin/python
    # a framework build ? https://matplotlib.org/faq/osx_framework.html 

fig, ax = pl.subplots()

Actual outcome

# If applicable, paste the console output here
#
#
IPython
matplotlib.__version__ : 2.1.0
pl.rcParams['backend'] : MacOSX
sys.version : 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 12:01:12) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Users/bz/py/etc/plot/mpl210.py in <module>()
     19 
     20 
---> 21 fig, ax = pl.subplots()
     22 

/Library/Python/2.7/site-packages/matplotlib/pyplot.pyc in subplots(nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw)
   1177     subplot
   1178     """
-> 1179     fig = figure(**fig_kw)
   1180     axs = fig.subplots(nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey,
   1181                        squeeze=squeeze, subplot_kw=subplot_kw,

/Library/Python/2.7/site-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, clear, **kwargs)
    554         # FigureManager base class.
    555         if matplotlib.is_interactive():
--> 556             draw_if_interactive()
    557 
    558         if _INSTALL_FIG_OBSERVER:

/Library/Python/2.7/site-packages/matplotlib/backend_bases.py in draw_if_interactive(cls)
    183             manager = Gcf.get_active()
    184             if manager:
--> 185                 cls.trigger_manager_draw(manager)
    186 
    187     @classmethod

TypeError: unbound method trigger_manager_draw() must be called with _BackendMac instance as first argument (got FigureManagerMac instance instead)

Expected outcome

used to work: 2.0.2

Matplotlib version

  • Operating system: 10.8.3
  • Matplotlib version: 2.1.0
  • Matplotlib backend (print(matplotlib.get_backend())): macosx
  • Python version: 2.7.14
  • Jupyter version (if applicable):
  • Other libraries:

pip install --upgrade --user matplotlib
python.org python-2.7.14-macosx10.6.pkg

Sorry if this a "framework build issue" which I don't understand, but 2.0.2 worked.

Also, kudos for the improved doc in 2.1 !

@denis-bz

This comment has been minimized.

Copy link
Author

commented Oct 10, 2017

Sorry sorry:
ipython --pylab -> no TypeError _BackendMac,
then pl.show() is necessary after pl.draw() .

thanks, cheers
-- denis

@denis-bz denis-bz closed this Oct 10, 2017

@WeatherGod

This comment has been minimized.

Copy link
Member

commented Oct 10, 2017

Just as a note, the ipython --pylab incantation is highly discouraged, and has been for several years now, because it causes imports to happen that does not appear in the session history, which leads to irreproducibility.

What do you mean by "pl.show() is necessary after pl.draw()"? Do you mean that you get an error, or that nothing happens until you do a pl.show()?

As for this traceback, I think we should still investigate it in order to figure out if we have some deeper problem.

@denis-bz

This comment has been minimized.

Copy link
Author

commented Oct 10, 2017

@jklymak

This comment has been minimized.

Copy link
Contributor

commented Oct 10, 2017

Can't reproduce using conda py2.7:

matplotlib.__version__ : 2.1.0
pl.rcParams['backend'] : MacOSX
sys.version : 2.7.14 |Anaconda custom (x86_64)| (default, Oct  5 2017, 02:28:52)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]

A plot doesn't show until I execute pl.show().

@WeatherGod

This comment has been minimized.

Copy link
Member

commented Oct 10, 2017

well, don' t drop it yet -- whatever it does, it works for me in macosx.

We aren't ipython, so we don't have any say. However, my understanding is that all it does is call from pylab import *. If you put that in first when you start up an ipython session, it should be equivalent to ipython --pylab. The point is that "explicit is better than implicit", by having the user specify the pylab import properly, rather than having ipython do it automatically for you.

As for the plot not showing until you do pl.show(), that is a matter of whether or not the interactive mode is turned on or not. We ship matplotlib with it turned off by default, so the figure doesn't show until you explicitly say pl.show(). However, this default behavior can be overridden in your matplotlibrc file. Did you change computers or something that would have caused you to have a new matplotlibrc file?

@anntzer anntzer referenced this issue Oct 10, 2017

Merged

Fix backend refactor #9347

0 of 6 tasks complete
@anntzer

This comment has been minimized.

Copy link
Contributor

commented Oct 10, 2017

xref #9347
my bad

@denis-bz

This comment has been minimized.

Copy link
Author

commented Oct 10, 2017

@denis-bz

This comment has been minimized.

Copy link
Author

commented Oct 11, 2017

A further comment: there seem to be 3 related questions:

  1. TypeError _BackendMac ...
    has anyone been able to reproduce this in python or ipython ?
  2. why does ipython --pylab lead to trigger_manager_draw( _BackendMac ) ?
  3. how do is_interactive / draw / show( block= ) work in mpl ?
    quite a few old Q+A on SO on this.
@tuanbui53

This comment has been minimized.

Copy link

commented Oct 19, 2017

On my macOS High Sierra, I upgraded to matplotlib 2.1.0.
In [15]: matplotlib.__version__ Out[15]: '2.1.0'
I start with command: ipython --pylab
Then when I type:
In [1]: figure()
This gives the error:
`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
----> 1 figure()

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, clear, **kwargs)
554 # FigureManager base class.
555 if matplotlib.is_interactive():
--> 556 draw_if_interactive()
557
558 if _INSTALL_FIG_OBSERVER:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/utils/decorators.pyc in wrapper(*args, **kw)
41 def wrapper(*args,**kw):
42 wrapper.called = False
---> 43 out = func(*args,**kw)
44 wrapper.called = True
45 return out

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in draw_if_interactive(cls)
183 manager = Gcf.get_active()
184 if manager:
--> 185 cls.trigger_manager_draw(manager)
186
187 @classmethod

TypeError: unbound method trigger_manager_draw() must be called with _BackendMac instance as first argument (got FigureManagerMac instance instead)`

@leewalsh

This comment has been minimized.

Copy link

commented Nov 1, 2017

Just to clarify: this bug is not caused by the pylab option, but rather by interactive (as in #9366 and #9489). So an easier workaround is to turn interactive off with plt.interactive(False):

leewalsh@what ~> ipython --pylab
Python 2.7.14 (default, Sep 25 2017, 09:53:22)
IPython 5.5.0 -- An enhanced Interactive Python.
Using matplotlib backend: MacOSX

In [1]: plt.interactive(False)

In [2]: plt.figure()
Out[2]: <matplotlib.figure.Figure at 0x10895f610>

In [3]: plt.show()

And an aside for those of us who like some auto import and interactive plots: you can have your cake and eat it too by setting InteractiveShellApp.pylab_import_all to False. This will load your matplotlib backend and set up interactive figures, and will import these modules:

# Import numpy as np/pyplot as plt are conventions we're trying to
# somewhat standardize on.  Making them available to users by default
# will greatly help this.
import numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot
np = numpy
plt = pyplot

... but will skip the * imports:

if import_all:
    from matplotlib.pylab import *
    from numpy import *

To get this, add this to your ipython_config.py:

c.InteractiveShellApp.pylab_import_all = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.