Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cartopy axes_grid_basic example broken by Matplotlib 3.6 #24053

Closed
@dopplershift

Description

@dopplershift

Cartopy'saxes_grid_basic was broken by Matplotlib 3.6. The relevant call is:

axgr=AxesGrid(fig,111,axes_class=axes_class,nrows_ncols=(3,2),axes_pad=0.6,cbar_location='right',cbar_mode='single',cbar_pad=0.2,cbar_size='3%',label_mode='')# note the empty label_mode

In#23550, we began explicitly checking for the documented values oflabel_mode, ('All', 'L', '1'), which this runs afoul of. It appears the previous code let'' (or any option not handled) essentially work as a noop forset_label_mode().

Based on the output when the example worked,'1' would be fine behavior-wise, but that currently produces in this example:

/Users/rmay/repos/cartopy/examples/miscellanea/axes_grid_basic.py:48: MatplotlibDeprecationWarning: The resize_event function was deprecated in Matplotlib 3.6 and will be removed two minor releases later. Use callbacks.process('resize_event', ResizeEvent(...)) instead.  fig = plt.figure()Traceback (most recent call last):  File"/Users/rmay/repos/cartopy/examples/miscellanea/axes_grid_basic.py", line78, in<module>    main()  File"/Users/rmay/repos/cartopy/examples/miscellanea/axes_grid_basic.py", line49, inmain    axgr= AxesGrid(fig,111,  File"/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line391, in__init__super().__init__(  File"/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line174, in__init__self.set_label_mode(label_mode)  File"/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line295, inset_label_mode    _tick_only(ax,bottom_on=True,left_on=True)  File"/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line16, in_tick_only    ax.axis["bottom"].toggle(ticklabels=bottom_off,label=bottom_off)TypeError:'method' object is not subscriptable

This is because, whileAxesGrid supposedly supports arbitrary classes by passingaxes_class, there's a huge caveat: the default ismpl_toolkits.axes_grid1.mpl_axes.Axes (TERRIBLY CONFUSING NAME--it's imported as justAxes inaxis_grid.py). This is a custom subclass that adds:

@propertydefaxis(self):returnself._axislinesdefclear(self):# docstring inheritedsuper().clear()# Init axis artists.self._axislines=self.AxisDict(self)self._axislines.update(bottom=SimpleAxisArtist(self.xaxis,1,self.spines["bottom"]),top=SimpleAxisArtist(self.xaxis,2,self.spines["top"]),left=SimpleAxisArtist(self.yaxis,1,self.spines["left"]),right=SimpleAxisArtist(self.yaxis,2,self.spines["right"]))

Options I can think of:

  1. Restore a noop option forset_label_mode
  2. FixAxesGrid to work more generally withaxes_class--monkey-patch/subclass to add the necessary modifications
  3. Document thataxes_class needs to have certain behavior
  4. FixAxesGrid to not rely on a property that OVERRIDESmatplotlib.axes.Axes.axis with adifferent type that also manually dispatches to the unboundaxis() method 😱
classAxisDict(dict):def__init__(self,axes):self.axes=axessuper().__init__()def__getitem__(self,k):ifisinstance(k,tuple):r=SimpleChainedObjects(# super() within a list comprehension needs explicit args.                    [super(Axes.AxisDict,self).__getitem__(k1)fork1ink])returnrelifisinstance(k,slice):ifk.startisNoneandk.stopisNoneandk.stepisNone:returnSimpleChainedObjects(list(self.values()))else:raiseValueError("Unsupported slice")else:returndict.__getitem__(self,k)def__call__(self,*v,**kwargs):returnmaxes.Axes.axis(self.axes,*v,**kwargs)

Anyone have any opinions?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp