Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
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:
- Restore a noop option for
set_label_mode
- Fix
AxesGrid
to work more generally withaxes_class
--monkey-patch/subclass to add the necessary modifications - Document that
axes_class
needs to have certain behavior - Fix
AxesGrid
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?