Title: Cartopy axes_grid_basic example broken by Matplotlib 3.6 · Issue #24053 · matplotlib/matplotlib · GitHub
Open Graph Title: Cartopy axes_grid_basic example broken by Matplotlib 3.6 · Issue #24053 · matplotlib/matplotlib
X Title: Cartopy axes_grid_basic example broken by Matplotlib 3.6 · Issue #24053 · matplotlib/matplotlib
Description: Cartopy's axes_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%', lab...
Open Graph Description: Cartopy's axes_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='si...
X Description: Cartopy's axes_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', c...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/24053
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cartopy axes_grid_basic example broken by Matplotlib 3.6","articleBody":"Cartopy's [axes_grid_basic](https://scitools.org.uk/cartopy/docs/latest/gallery/miscellanea/axes_grid_basic.html) was broken by Matplotlib 3.6. The relevant call is:\r\n```python\r\n axgr = AxesGrid(fig, 111, axes_class=axes_class,\r\n nrows_ncols=(3, 2),\r\n axes_pad=0.6,\r\n cbar_location='right',\r\n cbar_mode='single',\r\n cbar_pad=0.2,\r\n cbar_size='3%',\r\n label_mode='') # note the empty label_mode\r\n```\r\n\r\nIn #23550, we began explicitly checking for the documented values of `label_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 for `set_label_mode()`.\r\n\r\nBased on the output when the example worked, `'1'` would be fine behavior-wise, but that currently produces in this example:\r\n```pytb\r\n/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.\r\n fig = plt.figure()\r\nTraceback (most recent call last):\r\n File \"/Users/rmay/repos/cartopy/examples/miscellanea/axes_grid_basic.py\", line 78, in \u003cmodule\u003e\r\n main()\r\n File \"/Users/rmay/repos/cartopy/examples/miscellanea/axes_grid_basic.py\", line 49, in main\r\n axgr = AxesGrid(fig, 111,\r\n File \"/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py\", line 391, in __init__\r\n super().__init__(\r\n File \"/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py\", line 174, in __init__\r\n self.set_label_mode(label_mode)\r\n File \"/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py\", line 295, in set_label_mode\r\n _tick_only(ax, bottom_on=True, left_on=True)\r\n File \"/Users/rmay/miniconda3/envs/py310/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py\", line 16, in _tick_only\r\n ax.axis[\"bottom\"].toggle(ticklabels=bottom_off, label=bottom_off)\r\nTypeError: 'method' object is not subscriptable\r\n```\r\n\r\nThis is because, while `AxesGrid` supposedly supports arbitrary classes by passing `axes_class`, there's a huge caveat: the default is `mpl_toolkits.axes_grid1.mpl_axes.Axes` (TERRIBLY CONFUSING NAME--it's imported as just `Axes` in `axis_grid.py`). This is a custom subclass that adds:\r\n\r\n```python\r\n @property\r\n def axis(self):\r\n return self._axislines\r\n\r\n def clear(self):\r\n # docstring inherited\r\n super().clear()\r\n # Init axis artists.\r\n self._axislines = self.AxisDict(self)\r\n self._axislines.update(\r\n bottom=SimpleAxisArtist(self.xaxis, 1, self.spines[\"bottom\"]),\r\n top=SimpleAxisArtist(self.xaxis, 2, self.spines[\"top\"]),\r\n left=SimpleAxisArtist(self.yaxis, 1, self.spines[\"left\"]),\r\n right=SimpleAxisArtist(self.yaxis, 2, self.spines[\"right\"]))\r\n```\r\n\r\nOptions I can think of:\r\n1. Restore a noop option for `set_label_mode`\r\n2. Fix `AxesGrid` to work more generally with `axes_class`--monkey-patch/subclass to add the necessary modifications\r\n3. Document that `axes_class` needs to have certain behavior\r\n4. Fix `AxesGrid` to not rely on a property that OVERRIDES `matplotlib.axes.Axes.axis` with a *different type* that also manually dispatches to the unbound `axis()` method :scream: \r\n```python\r\n class AxisDict(dict):\r\n def __init__(self, axes):\r\n self.axes = axes\r\n super().__init__()\r\n\r\n def __getitem__(self, k):\r\n if isinstance(k, tuple):\r\n r = SimpleChainedObjects(\r\n # super() within a list comprehension needs explicit args.\r\n [super(Axes.AxisDict, self).__getitem__(k1) for k1 in k])\r\n return r\r\n elif isinstance(k, slice):\r\n if k.start is None and k.stop is None and k.step is None:\r\n return SimpleChainedObjects(list(self.values()))\r\n else:\r\n raise ValueError(\"Unsupported slice\")\r\n else:\r\n return dict.__getitem__(self, k)\r\n\r\n def __call__(self, *v, **kwargs):\r\n return maxes.Axes.axis(self.axes, *v, **kwargs)\r\n```\r\n\r\nAnyone have any opinions?","author":{"url":"https://github.com/dopplershift","@type":"Person","name":"dopplershift"},"datePublished":"2022-09-29T18:46:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/24053/matplotlib/issues/24053"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:67377ac9-5b84-4ce8-0d6f-19947ed62494 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 96BE:14F57:36A25:4BD1A:6A50EA7E |
| html-safe-nonce | 5ef3172d99b2a07153ec186f513869b81075dbb7ab73e568522b36a747cadbcf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkJFOjE0RjU3OjM2QTI1OjRCRDFBOjZBNTBFQTdFIiwidmlzaXRvcl9pZCI6IjY1OTE3MDg2ODcxODE2MDU1MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7afbed77c304630e332f897c5baeda7d4309ec83205312994086c7e08b88b2c5 |
| hovercard-subject-tag | issue:1391335444 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/24053/issue_layout |
| twitter:image | https://opengraph.githubassets.com/846d312401148cfce6bc0f511546def8c19bea4d96991009744ebc5b0637afc2/matplotlib/matplotlib/issues/24053 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/846d312401148cfce6bc0f511546def8c19bea4d96991009744ebc5b0637afc2/matplotlib/matplotlib/issues/24053 |
| og:image:alt | Cartopy's axes_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='si... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dopplershift |
| hostname | github.com |
| expected-hostname | github.com |
| None | 72b13e0e8d0319acdd27a145cfe73f4f06c791713d0ac4690e41fb68ad28cac0 |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fb19d617b534959801b4b7453938ecf1dfa22131 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width