Skip to content

[Doc]: matplotlib.axes.Axes.table bbox parameter #25048

@HealthyPear

Description

@HealthyPear

Documentation Link

https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.table.html#matplotlib.axes.Axes.table

Problem

The documentation states that bbox should be an instance of matplotlib.transforms.Bbox.

When I try to use it like this I obtain the following error traceback below using matplotlib v3.6.2, whereas it works if I define it as e.g. bbox=[1, 1, 1, 1] which I guess (but just because I tried empirically) is equivalent to the method from_bounds() of Bbox.

TypeError                                 Traceback (most recent call last)
File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/IPython/core/formatters.py:972, in MimeBundleFormatter.__call__(self, obj, include, exclude)
    969     method = get_real_method(obj, self.print_method)
    971     if method is not None:
--> 972         return method(include=include, exclude=exclude)
    973     return None
    974 else:

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/ipympl/backend_nbagg.py:336, in Canvas._repr_mimebundle_(self, **kwargs)
    333     plaintext = plaintext[:110] + '…'
    335 buf = io.BytesIO()
--> 336 self.figure.savefig(buf, format='png', dpi='figure')
    338 base64_image = b64encode(buf.getvalue()).decode('utf-8')
    339 self._data_url = f'[data:image/png;base64,{](data:image/png;base64,{base64_image)[base64_image](data:image/png;base64,{base64_image)}'

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/figure.py:3274, in Figure.savefig(self, fname, transparent, **kwargs)
   3270     for ax in self.axes:
   3271         stack.enter_context(
   3272             ax.patch._cm_set(facecolor='none', edgecolor='none'))
-> 3274 self.canvas.print_figure(fname, **kwargs)

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/backend_bases.py:2338, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2334 try:
   2335     # _get_renderer may change the figure dpi (as vector formats
   2336     # force the figure dpi to 72), so we need to set it again here.
   2337     with cbook._setattr_cm(self.figure, dpi=dpi):
-> 2338         result = print_method(
   2339             filename,
   2340             facecolor=facecolor,
   2341             edgecolor=edgecolor,
   2342             orientation=orientation,
   2343             bbox_inches_restore=_bbox_inches_restore,
   2344             **kwargs)
   2345 finally:
   2346     if bbox_inches and restore_bbox:

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/backend_bases.py:2204, in FigureCanvasBase._switch_canvas_and_return_print_method.<locals>.<lambda>(*args, **kwargs)
   2200     optional_kws = {  # Passed by print_figure for other renderers.
   2201         "dpi", "facecolor", "edgecolor", "orientation",
   2202         "bbox_inches_restore"}
   2203     skip = optional_kws - {*inspect.signature(meth).parameters}
-> 2204     print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
   2205         *args, **{k: v for k, v in kwargs.items() if k not in skip}))
   2206 else:  # Let third-parties do as they see fit.
   2207     print_method = meth

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/_api/deprecation.py:410, in delete_parameter.<locals>.wrapper(*inner_args, **inner_kwargs)
    400     deprecation_addendum = (
    401         f"If any parameter follows {name!r}, they should be passed as "
    402         f"keyword, not positionally.")
    403     warn_deprecated(
    404         since,
    405         name=repr(name),
   (...)
    408                  else deprecation_addendum,
    409         **kwargs)
--> 410 return func(*inner_args, **inner_kwargs)

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:517, in FigureCanvasAgg.print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
    468 @_api.delete_parameter("3.5", "args")
    469 def print_png(self, filename_or_obj, *args,
    470               metadata=None, pil_kwargs=None):
    471     """
    472     Write the figure to a PNG file.
    473 
   (...)
    515         *metadata*, including the default 'Software' key.
    516     """
--> 517     self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:463, in FigureCanvasAgg._print_pil(self, filename_or_obj, fmt, pil_kwargs, metadata)
    458 def _print_pil(self, filename_or_obj, fmt, pil_kwargs, metadata=None):
    459     """
    460     Draw the canvas, then save it using `.image.imsave` (to which
    461     *pil_kwargs* and *metadata* are forwarded).
    462     """
--> 463     FigureCanvasAgg.draw(self)
    464     mpl.image.imsave(
    465         filename_or_obj, self.buffer_rgba(), format=fmt, origin="upper",
    466         dpi=self.figure.dpi, metadata=metadata, pil_kwargs=pil_kwargs)

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py:405, in FigureCanvasAgg.draw(self)
    401 # Acquire a lock on the shared font cache.
    402 with RendererAgg.lock, \
    403      (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
    404       else nullcontext()):
--> 405     self.figure.draw(self.renderer)
    406     # A GUI class may be need to update a window using this draw, so
    407     # don't forget to call the superclass.
    408     super().draw()

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/artist.py:74, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
     72 @wraps(draw)
     73 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 74     result = draw(artist, renderer, *args, **kwargs)
     75     if renderer._rasterizing:
     76         renderer.stop_rasterizing()

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/artist.py:51, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     48     if artist.get_agg_filter() is not None:
     49         renderer.start_filter()
---> 51     return draw(artist, renderer)
     52 finally:
     53     if artist.get_agg_filter() is not None:

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/figure.py:3071, in Figure.draw(self, renderer)
   3068         # ValueError can occur when resizing a window.
   3070 self.patch.draw(renderer)
-> 3071 mimage._draw_list_compositing_images(
   3072     renderer, self, artists, self.suppressComposite)
   3074 for sfig in self.subfigs:
   3075     sfig.draw(renderer)

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    129 if not_composite or not has_images:
    130     for a in artists:
--> 131         a.draw(renderer)
    132 else:
    133     # Composite any adjacent images together
    134     image_group = []

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/artist.py:51, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     48     if artist.get_agg_filter() is not None:
     49         renderer.start_filter()
---> 51     return draw(artist, renderer)
     52 finally:
     53     if artist.get_agg_filter() is not None:

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/axes/_base.py:3107, in _AxesBase.draw(self, renderer)
   3104         a.draw(renderer)
   3105     renderer.stop_rasterizing()
-> 3107 mimage._draw_list_compositing_images(
   3108     renderer, self, artists, self.figure.suppressComposite)
   3110 renderer.close_group('axes')
   3111 self.stale = False

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    129 if not_composite or not has_images:
    130     for a in artists:
--> 131         a.draw(renderer)
    132 else:
    133     # Composite any adjacent images together
    134     image_group = []

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/artist.py:51, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     48     if artist.get_agg_filter() is not None:
     49         renderer.start_filter()
---> 51     return draw(artist, renderer)
     52 finally:
     53     if artist.get_agg_filter() is not None:

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/table.py:409, in Table.draw(self, renderer)
    407     return
    408 renderer.open_group('table', gid=self.get_gid())
--> 409 self._update_positions(renderer)
    411 for key in sorted(self._cells):
    412     self._cells[key].draw(renderer)

File ~/Applications/mambaforge/envs/swgo-plot/lib/python3.9/site-packages/matplotlib/table.py:598, in Table._update_positions(self, renderer)
    594 l, b, w, h = bbox.bounds
    596 if self._bbox is not None:
    597     # Position according to bbox
--> 598     rl, rb, rw, rh = self._bbox
    599     self.scale(rw / w, rh / h)
    600     ox = rl - l

TypeError: cannot unpack non-iterable Bbox object
Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous view', 'arrow-left', 'back'), ('Forward', 'Forward to next view', 'arrow-right', 'forward'), ('Pan', 'Left button pans, Right button zooms\nx/y fixes axis, CTRL fixes aspect', 'arrows', 'pan'), ('Zoom', 'Zoom to rectangle\nx/y fixes axis', 'square-o', 'zoom'), ('Download', 'Download plot', 'floppy-o', 'save_figure')]))

Suggested improvement

Either let the parameter be a proper BBox (my suggestion) or specify that the usage is that of from_bounds()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy