Skip to content

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

Closed

Description

@denis-bz

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 !

Activity

  1. denis-bz commented on Oct 10, 2017

    @denis-bz
    Author

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

    thanks, cheers
    -- denis

  2. WeatherGod commented on Oct 10, 2017

    @WeatherGod
    Member

    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.

  3. denis-bz commented on Oct 10, 2017

    @denis-bz
    Author
  4. jklymak commented on Oct 10, 2017

    @jklymak
    Member

    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().

  5. WeatherGod commented on Oct 10, 2017

    @WeatherGod
    Member

    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?

  6. anntzer commented on Oct 10, 2017

    @anntzer
    Contributor

    xref #9347
    my bad

  7. denis-bz commented on Oct 10, 2017

    @denis-bz
    Author
  8. denis-bz commented on Oct 11, 2017

    @denis-bz
    Author

    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.
  9. tuanbui53 commented on Oct 19, 2017

    @tuanbui53

    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)`

  10. leewalsh commented on Nov 1, 2017

    @leewalsh

    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
  11. added this to the v2.1.1 milestone on Dec 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions