Title: [Bug]: Inset Axes Failing for Geographic Plot · Issue #29720 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Inset Axes Failing for Geographic Plot · Issue #29720 · matplotlib/matplotlib
X Title: [Bug]: Inset Axes Failing for Geographic Plot · Issue #29720 · matplotlib/matplotlib
Description: Bug summary I'm trying to work with the inset_axes() function for the first time, using geographic data plotted with matplotlib and CartoPy, but have been running into a variety of issues. For simplicity's sake, point #3 on #29174 is a g...
Open Graph Description: Bug summary I'm trying to work with the inset_axes() function for the first time, using geographic data plotted with matplotlib and CartoPy, but have been running into a variety of issues. For simp...
X Description: Bug summary I'm trying to work with the inset_axes() function for the first time, using geographic data plotted with matplotlib and CartoPy, but have been running into a variety of issues. For ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/29720
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Inset Axes Failing for Geographic Plot","articleBody":"### Bug summary\n\nI'm trying to work with the `inset_axes()` function for the first time, using geographic data plotted with matplotlib and CartoPy, but have been running into a variety of issues. For simplicity's sake, point #3 on #29174 is a good representation of what I am trying to do (recreated below).\n\n### Code for reproduction\n\n```Python\nimport matplotlib.pyplot as plt\nimport cartopy.crs as ccrs\nimport cartopy.feature as cfeature\n\nmain_map_proj = ccrs.TransverseMercator()\npcarree = ccrs.PlateCarree()\n\nfig, ax = plt.subplots(subplot_kw={\"projection\": main_map_proj})\n\nax.set_extent([-50, 15, 50, 70], crs=pcarree)\nax.add_feature(cfeature.OCEAN.with_scale('50m'), facecolor=\"lightsteelblue\", zorder=1,\n edgecolor=\"k\", lw=0.2)\n\ninset_ax = ax.inset_axes((0.05, 0.05, 0.3, 0.3), projection=pcarree)\n\ninset_extent = [-44, -38, 63, 66]\ninset_ax.set_extent(inset_extent, crs=pcarree)\ninset_ax.add_feature(cfeature.OCEAN, facecolor=\"lightsteelblue\", zorder=1)\n\nax.indicate_inset_zoom(inset_ax, edgecolor=\"black\", transform=pcarree)\n\nx = [inset_extent[0], inset_extent[1], inset_extent[1], inset_extent[0]]\ny = [inset_extent[2], inset_extent[2], inset_extent[3], inset_extent[3]]\nfor a in ax, inset_ax:\n a.scatter(x, y, c=range(4), s=150, transform=pcarree)\n\nplt.show()\n```\n\n### Actual outcome\n\n`ValueError: Axes should be an instance of GeoAxes, got \u003cclass 'NoneType'\u003e`.\n\nThis is happening even though I am verifying that both `ax` and `inset_ax` are GeoAxes using `type()`.\n\n### Expected outcome\n\n\n\n### Additional information\n\nI am posting this in matplotlib as it _seems_ to be more of an issue with the `inset_axes()` function rather than the `GeoAxes` class.\n\n\u003cdetails\u003e\n\u003csummary\u003eFull Stack Trace \u003e\u003c/summary\u003e\n\n```py\n---------------------------------------------------------------------------\nValueError Traceback (most recent call last)\nFile \\personalpath\\to\\env\\site-packages\\IPython\\core\\formatters.py:402, in BaseFormatter.__call__(self, obj)\n 400 pass\n 401 else:\n--\u003e 402 return printer(obj)\n 403 # Finally look for special method names\n 404 method = get_real_method(obj, self.print_method)\n\nFile \\personalpath\\to\\env\\site-packages\\IPython\\core\\pylabtools.py:170, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)\n 167 from matplotlib.backend_bases import FigureCanvasBase\n 168 FigureCanvasBase(fig)\n--\u003e 170 fig.canvas.print_figure(bytes_io, **kw)\n 171 data = bytes_io.getvalue()\n 172 if fmt == 'svg':\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\backend_bases.py:2155, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)\n 2152 # we do this instead of `self.figure.draw_without_rendering`\n 2153 # so that we can inject the orientation\n 2154 with getattr(renderer, \"_draw_disabled\", nullcontext)():\n-\u003e 2155 self.figure.draw(renderer)\n 2156 if bbox_inches:\n 2157 if bbox_inches == \"tight\":\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\artist.py:94, in _finalize_rasterization.\u003clocals\u003e.draw_wrapper(artist, renderer, *args, **kwargs)\n 92 @wraps(draw)\n 93 def draw_wrapper(artist, renderer, *args, **kwargs):\n---\u003e 94 result = draw(artist, renderer, *args, **kwargs)\n 95 if renderer._rasterizing:\n 96 renderer.stop_rasterizing()\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\artist.py:71, in allow_rasterization.\u003clocals\u003e.draw_wrapper(artist, renderer)\n 68 if artist.get_agg_filter() is not None:\n 69 renderer.start_filter()\n---\u003e 71 return draw(artist, renderer)\n 72 finally:\n 73 if artist.get_agg_filter() is not None:\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\figure.py:3257, in Figure.draw(self, renderer)\n 3254 # ValueError can occur when resizing a window.\n 3256 self.patch.draw(renderer)\n-\u003e 3257 mimage._draw_list_compositing_images(\n 3258 renderer, self, artists, self.suppressComposite)\n 3260 renderer.close_group('figure')\n 3261 finally:\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\image.py:134, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)\n 132 if not_composite or not has_images:\n 133 for a in artists:\n--\u003e 134 a.draw(renderer)\n 135 else:\n 136 # Composite any adjacent images together\n 137 image_group = []\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\artist.py:71, in allow_rasterization.\u003clocals\u003e.draw_wrapper(artist, renderer)\n 68 if artist.get_agg_filter() is not None:\n 69 renderer.start_filter()\n---\u003e 71 return draw(artist, renderer)\n 72 finally:\n 73 if artist.get_agg_filter() is not None:\n\nFile \\personalpath\\to\\env\\site-packages\\cartopy\\mpl\\geoaxes.py:524, in GeoAxes.draw(self, renderer, **kwargs)\n 519 self.imshow(img, extent=extent, origin=origin,\n 520 transform=factory.crs, *factory_args[1:],\n 521 **factory_kwargs)\n 522 self._done_img_factory = True\n--\u003e 524 return super().draw(renderer=renderer, **kwargs)\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\artist.py:71, in allow_rasterization.\u003clocals\u003e.draw_wrapper(artist, renderer)\n 68 if artist.get_agg_filter() is not None:\n 69 renderer.start_filter()\n---\u003e 71 return draw(artist, renderer)\n 72 finally:\n 73 if artist.get_agg_filter() is not None:\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\axes\\_base.py:3210, in _AxesBase.draw(self, renderer)\n 3207 if artists_rasterized:\n 3208 _draw_rasterized(self.get_figure(root=True), artists_rasterized, renderer)\n-\u003e 3210 mimage._draw_list_compositing_images(\n 3211 renderer, self, artists, self.get_figure(root=True).suppressComposite)\n 3213 renderer.close_group('axes')\n 3214 self.stale = False\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\image.py:134, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)\n 132 if not_composite or not has_images:\n 133 for a in artists:\n--\u003e 134 a.draw(renderer)\n 135 else:\n 136 # Composite any adjacent images together\n 137 image_group = []\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\artist.py:38, in _prevent_rasterization.\u003clocals\u003e.draw_wrapper(artist, renderer, *args, **kwargs)\n 35 renderer.stop_rasterizing()\n 36 renderer._rasterizing = False\n---\u003e 38 return draw(artist, renderer, *args, **kwargs)\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\inset.py:230, in InsetIndicator.draw(self, renderer)\n 226 conn_same_style = []\n 228 # Figure out which connectors have the same style as the box, so should\n 229 # be drawn as a single path.\n--\u003e 230 for conn in self.connectors or []:\n 231 if conn.get_visible():\n 232 drawn = False\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\inset.py:221, in InsetIndicator.connectors(self)\n 219 if self._auto_update_bounds:\n 220 self._rectangle.set_bounds(self._bounds_from_inset_ax())\n--\u003e 221 self._update_connectors()\n 222 return tuple(self._connectors)\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\inset.py:192, in InsetIndicator._update_connectors(self)\n 189 pos = self._inset_ax.get_position()\n 190 bboxins = pos.transformed(self.get_figure(root=False).transSubfigure)\n 191 rectbbox = transforms.Bbox.from_bounds(x, y, width, height).transformed(\n--\u003e 192 self._rectangle.get_transform())\n 193 x0 = rectbbox.x0 \u003c bboxins.x0\n 194 x1 = rectbbox.x1 \u003c bboxins.x1\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\patches.py:309, in Patch.get_transform(self)\n 307 def get_transform(self):\n 308 \"\"\"Return the `~.transforms.Transform` applied to the `Patch`.\"\"\"\n--\u003e 309 return self.get_patch_transform() + artist.Artist.get_transform(self)\n\nFile \\personalpath\\to\\env\\site-packages\\matplotlib\\artist.py:454, in Artist.get_transform(self)\n 451 self._transform = IdentityTransform()\n 452 elif (not isinstance(self._transform, Transform)\n 453 and hasattr(self._transform, '_as_mpl_transform')):\n--\u003e 454 self._transform = self._transform._as_mpl_transform(self.axes)\n 455 return self._transform\n\nFile \\personalpath\\to\\env\\site-packages\\cartopy\\crs.py:267, in CRS._as_mpl_transform(self, axes)\n 265 import cartopy.mpl.geoaxes as geoaxes\n 266 if not isinstance(axes, geoaxes.GeoAxes):\n--\u003e 267 raise ValueError(\n 268 'Axes should be an instance of GeoAxes, got %s' % type(axes)\n 269 )\n 270 return (\n 271 geoaxes.InterProjectionTransform(self, axes.projection) +\n 272 axes.transData\n 273 )\n\nValueError: Axes should be an instance of GeoAxes, got \u003cclass 'NoneType'\u003e\n```\n\n\u003c/details\u003e\n\n### Operating system\n\n_No response_\n\n### Matplotlib Version\n\n3.10.1\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n3.12.9\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nconda","author":{"url":"https://github.com/moss-xyz","@type":"Person","name":"moss-xyz"},"datePublished":"2025-03-09T03:59:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/29720/matplotlib/issues/29720"}
| 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:5fdf25f2-a6bf-a26d-029f-b8ab2651645f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC18:25680F:2198EA:2DE3BA:6A51D677 |
| html-safe-nonce | 65e61e1a00597771be2b864fe32fe82ca8cf774986ad3bdc83c0b9e512208241 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzE4OjI1NjgwRjoyMTk4RUE6MkRFM0JBOjZBNTFENjc3IiwidmlzaXRvcl9pZCI6IjMyMjY5MzM3ODU5Njc4NDI5MzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f7164511490ce40a0f1c7b8fd81196793361242fd2bd043f8a7194c9cfc3db8d |
| hovercard-subject-tag | issue:2905183858 |
| 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/29720/issue_layout |
| twitter:image | https://opengraph.githubassets.com/62523e896d428a4d9f327bed4ac55ea5b01621b50968edf8bf06dd6132ddc50c/matplotlib/matplotlib/issues/29720 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/62523e896d428a4d9f327bed4ac55ea5b01621b50968edf8bf06dd6132ddc50c/matplotlib/matplotlib/issues/29720 |
| og:image:alt | Bug summary I'm trying to work with the inset_axes() function for the first time, using geographic data plotted with matplotlib and CartoPy, but have been running into a variety of issues. For simp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | moss-xyz |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width