Skip to content

axes_grid1 axes have no keyword argument 'bbox_extra_artists' #12634

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

Closed
astrojuanlu opened this issue Oct 26, 2018 · 5 comments · Fixed by #12635
Closed

axes_grid1 axes have no keyword argument 'bbox_extra_artists' #12634

astrojuanlu opened this issue Oct 26, 2018 · 5 comments · Fixed by #12635
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout topic: mpl_toolkit
Milestone

Comments

@astrojuanlu
Copy link

Bug report

Bug summary

A regression was introduced from v3.0.0 and v3.0.1 that breaks axes_grid1 with a TypeError: get_tightbbox() got an unexpected keyword argument 'bbox_extra_artists'.

Code for reproduction

import matplotlib.pyplot as plt
plt.ion()

from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset

fig, ax = plt.subplots(figsize=(8, 6))

l, = ax.plot([1, 2, 3], [0, 1, 0])

ax_zoom = zoomed_inset_axes(ax, 4)
ax_zoom.plot([1, 2, 3], [0, 1, 0])

mark_inset(ax, ax_zoom, loc1=1, loc2=3, fc="none", ec='0.3')

fig.savefig("/tmp/tmp.png")

Actual outcome

TypeError                                 Traceback (most recent call last)
~/.miniconda36/envs/poliastro37/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

~/.miniconda36/envs/poliastro37/lib/python3.7/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
    239 
    240     if 'png' in formats:
--> 241         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    242     if 'retina' in formats or 'png2x' in formats:
    243         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

~/.miniconda36/envs/poliastro37/lib/python3.7/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    123 
    124     bytes_io = BytesIO()
--> 125     fig.canvas.print_figure(bytes_io, **kw)
    126     data = bytes_io.getvalue()
    127     if fmt == 'svg':

~/.miniconda36/envs/poliastro37/lib/python3.7/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
   2051                     bbox_artists = kwargs.pop("bbox_extra_artists", None)
   2052                     bbox_inches = self.figure.get_tightbbox(renderer,
-> 2053                             bbox_extra_artists=bbox_artists)
   2054                     pad = kwargs.pop("pad_inches", None)
   2055                     if pad is None:

~/.miniconda36/envs/poliastro37/lib/python3.7/site-packages/matplotlib/figure.py in get_tightbbox(self, renderer, bbox_extra_artists)
   2274         bb.extend(
   2275             ax.get_tightbbox(renderer, bbox_extra_artists=bbox_extra_artists)
-> 2276             for ax in self.axes if ax.get_visible())
   2277 
   2278         if len(bb) == 0:

~/.miniconda36/envs/poliastro37/lib/python3.7/site-packages/matplotlib/figure.py in <genexpr>(.0)
   2274         bb.extend(
   2275             ax.get_tightbbox(renderer, bbox_extra_artists=bbox_extra_artists)
-> 2276             for ax in self.axes if ax.get_visible())
   2277 
   2278         if len(bb) == 0:

TypeError: get_tightbbox() got an unexpected keyword argument 'bbox_extra_artists'

<Figure size 576x432 with 2 Axes>

Expected outcome

This worked in version v3.0.0.

Matplotlib version

  • Operating system: Linux Mint (latest)
  • Matplotlib version: v3.0.1
  • Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
  • Python version: 3.7.0
  • Jupyter version (if applicable): 5.7.0 (notebook)
  • Other libraries:

Installed using pip.

@jklymak
Copy link
Member

jklymak commented Oct 26, 2018

I cannot reproduce with the code above, thought I didn't try with the inline backend. I do get a wonky looking figure, but I don't throw an error.

@jklymak
Copy link
Member

jklymak commented Oct 26, 2018

OK. I see - you forgot to specify fig.savefig("/tmp/tmp.png", box_inches='tight')

@jklymak jklymak added topic: geometry manager LayoutEngine, Constrained layout, Tight layout topic: mpl_toolkit labels Oct 26, 2018
@jklymak jklymak added this to the v3.0.x milestone Oct 26, 2018
@tylerharvey
Copy link

I get the same error in 3.0.1 with inset_axes(). I see that they're supposed to be experimental now, but the code I'm using worked before 3.0.0 (I don't remember if I ran it with 3.0.0 as well).

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
fig = plt.figure()
ax1 = plt.gca()
ax1.plot(np.arange(10))
inset_ax1 = inset_axes(ax1,width="50%",height=0.6)
inset_ax1.plot(np.arange(10))
plt.savefig('inset_axes_test',pad_inches=0,bbox_inches='tight')

Outcome:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/pyplot.py", line 689, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/figure.py", line 2094, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/backend_bases.py", line 2053, in print_figure
    bbox_extra_artists=bbox_artists)
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/figure.py", line 2276, in get_tightbbox
    for ax in self.axes if ax.get_visible())
  File "/usr/local/lib/python3.5/dist-packages/matplotlib/figure.py", line 2276, in <genexpr>
    for ax in self.axes if ax.get_visible())
TypeError: get_tightbbox() got an unexpected keyword argument 'bbox_extra_artists'

I get no bug with bbox_inches=0 or None.

@jklymak
Copy link
Member

jklymak commented Dec 11, 2018

I don’t think this was fixed until 3.0.2, but I could be wrong.

The experimental inset_axes is not imported from axes_grid1. It is just a method on axes. I.e. inset = ax1.inset_axes().

@tylerharvey
Copy link

Yep, you're right that it's fixed in 3.0.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout topic: mpl_toolkit
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants