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

AttributeError: 'FigureCanvasAgg' object has no attribute 'invalidate' #4156

Closed
dmnd opened this issue Feb 25, 2015 · 9 comments
Closed

AttributeError: 'FigureCanvasAgg' object has no attribute 'invalidate' #4156

dmnd opened this issue Feb 25, 2015 · 9 comments
Labels
status: needs clarification Issues that need more information to resolve.

Comments

@dmnd
Copy link

dmnd commented Feb 25, 2015

I'm not sure if this is an iPython or matplotlib or pandas issue. But running this seemingly correct looking code gives a stacktrace. I saw a StackOverflow question about it, but no bug had been reported.

%matplotlib inline 
import matplotlib.pylab

import pandas
ser = pandas.Series(range(10), pandas.date_range(end='2014-01-01', periods=10))
ser.plot()

The plot is actually generated, but there's a big stacktrace too:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-6ead4fd157ae> in <module>()
      5 import pandas
      6 ser = pandas.Series(range(10), pandas.date_range(end='2014-01-01', periods=10))
----> 7 ser.plot()

/Users/dmnd/.virtualenvs/ipy/lib/python2.7/site-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
   2509                  yerr=yerr, xerr=xerr,
   2510                  label=label, secondary_y=secondary_y,
-> 2511                  **kwds)
   2512 
   2513 

/Users/dmnd/.virtualenvs/ipy/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
   2315         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
   2316 
-> 2317     plot_obj.generate()
   2318     plot_obj.draw()
   2319     return plot_obj.result

/Users/dmnd/.virtualenvs/ipy/lib/python2.7/site-packages/pandas/tools/plotting.pyc in generate(self)
    921         self._compute_plot_data()
    922         self._setup_subplots()
--> 923         self._make_plot()
    924         self._add_table()
    925         self._make_legend()

/Users/dmnd/.virtualenvs/ipy/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _make_plot(self)
   1609             kwds['label'] = label
   1610 
-> 1611             newlines = plotf(ax, x, y, style=style, column_num=i, **kwds)
   1612             self._add_legend_handle(newlines[0], label, index=i)
   1613 

/Users/dmnd/.virtualenvs/ipy/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(ax, x, data, style, **kwds)
   1646             # accept x to be consistent with normal plot func,
   1647             # x is not passed to tsplot as it uses data.index as x coordinate
-> 1648             lines = tsplot(data, plotf, ax=ax, style=style, **kwds)
   1649             return lines
   1650         return _plot

/Users/dmnd/.virtualenvs/ipy/lib/python2.7/site-packages/pandas/tseries/plotting.pyc in tsplot(series, plotf, **kwargs)
     65 
     66     # set date formatter, locators and rescale limits
---> 67     format_dateaxis(ax, ax.freq)
     68 
     69     # x and y coord info

/Users/dmnd/.virtualenvs/ipy/lib/python2.7/site-packages/pandas/tseries/plotting.pyc in format_dateaxis(subplot, freq)
    224     subplot.xaxis.set_major_formatter(majformatter)
    225     subplot.xaxis.set_minor_formatter(minformatter)
--> 226     pylab.draw_if_interactive()

/Users/dmnd/.virtualenvs/ipy/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

/Users/dmnd/.virtualenvs/ipy/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.pyc in draw_if_interactive()
    235         figManager =  Gcf.get_active()
    236         if figManager is not None:
--> 237             figManager.canvas.invalidate()
    238 
    239 

AttributeError: 'FigureCanvasAgg' object has no attribute 'invalidate'

Here's what I have installed:

$ pip freeze
Jinja2==2.7.3
MarkupSafe==0.23
backports.ssl-match-hostname==3.4.0.2
certifi==14.05.14
ipython==2.4.1
matplotlib==1.4.3
mock==1.0.1
nose==1.3.4
numpy==1.9.1
pandas==0.15.2
pyparsing==2.0.3
python-dateutil==2.4.0
pytz==2014.10
pyzmq==14.5.0
six==1.9.0
tornado==4.1
wsgiref==0.1.2

$ python -V
Python 2.7.8

I also reported this as ipython/ipython#7864

@dmnd
Copy link
Author

dmnd commented Feb 25, 2015

In the StackOverflow question @tacaswell asked for this:

In [4]: matplotlib.get_backend()
Out[4]: 'module://IPython.kernel.zmq.pylab.backend_inline'

@takluyver
Copy link
Contributor

It looks like something is confused about which backend is in use - the last frame of the traceback is in backend_macosx, but it reports that the IPython inline backend is in use.

@tacaswell we're aiming to release IPython 3.0 on Friday, so if the bug is in IPython code, it would be good to know that quickly, to see if we can slip a simple fix in.

@tacaswell
Copy link
Member

I don't have (easy) access to a mac to try and reproduce this.

@dmnd What are the versions of everything involved? Does this happen every time? Does this happen if you start with a fresh notebook? Do you have any auto-imports for python start up that import pyplot?

I don't think we claim to support switching which interactive backend pyplot is using once it has been imported. One thing to do might to have the magic watch for the warning that comes out if you call use after pyplot has been imported.

@tacaswell tacaswell added this to the unassigned milestone Feb 25, 2015
@tacaswell tacaswell added the status: needs clarification Issues that need more information to resolve. label Feb 25, 2015
@dmnd
Copy link
Author

dmnd commented Feb 25, 2015

Do you have any auto-imports for python start up that import pyplot?

@tacaswell thanks for your help! I think this is because I was starting the notebook with ipython notebook --pylab. If I omit the --pylab, things work properly.

I noticed now that there is a warning emitted when you use --pylab, but I didn't notice it until now. Maybe it can be made red or something.

@dmnd dmnd closed this as completed Feb 25, 2015
@takluyver
Copy link
Contributor

Maybe it can be made red or something.

We've gone one better - in version 3 the notebook refuses to start with --pylab.

@tacaswell I think IPython aims to support at least switching between the inline backend and a single interactive GUI backend within a session, so there may still be something to work out here.

@dmnd
Copy link
Author

dmnd commented Feb 26, 2015

We've gone one better - in version 3 the notebook refuses to start with --pylab.

😌

@tacaswell
Copy link
Member

@takluyver I am utterly swamped today and tomorrow, I don't have any bandwidth to devote to this.

@jenshnielsen
Copy link
Member

Switching back and forth between the OSX and inline backend with this example works as expected for me.

Python 2.7.9
IPython 3.0rc1
Matplotlib 1.4.3

@takluyver
Copy link
Contributor

OK, we'll leave the issue open on our side, but we won't hold 3.0 up for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs clarification Issues that need more information to resolve.
Projects
None yet
Development

No branches or pull requests

4 participants