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

[Bug]: Inset Axes Failing for Geographic Plot #29720

Closed
Milestone
@moss-xyz

Description

@moss-xyz

Bug summary

I'm trying to work with theinset_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).

Code for reproduction

importmatplotlib.pyplotaspltimportcartopy.crsasccrsimportcartopy.featureascfeaturemain_map_proj=ccrs.TransverseMercator()pcarree=ccrs.PlateCarree()fig,ax=plt.subplots(subplot_kw={"projection":main_map_proj})ax.set_extent([-50,15,50,70],crs=pcarree)ax.add_feature(cfeature.OCEAN.with_scale('50m'),facecolor="lightsteelblue",zorder=1,edgecolor="k",lw=0.2)inset_ax=ax.inset_axes((0.05,0.05,0.3,0.3),projection=pcarree)inset_extent= [-44,-38,63,66]inset_ax.set_extent(inset_extent,crs=pcarree)inset_ax.add_feature(cfeature.OCEAN,facecolor="lightsteelblue",zorder=1)ax.indicate_inset_zoom(inset_ax,edgecolor="black",transform=pcarree)x= [inset_extent[0],inset_extent[1],inset_extent[1],inset_extent[0]]y= [inset_extent[2],inset_extent[2],inset_extent[3],inset_extent[3]]forainax,inset_ax:a.scatter(x,y,c=range(4),s=150,transform=pcarree)plt.show()

Actual outcome

ValueError: Axes should be an instance of GeoAxes, got <class 'NoneType'>.

This is happening even though I am verifying that bothax andinset_ax are GeoAxes usingtype().

Expected outcome

Image

Additional information

I am posting this in matplotlib as itseems to be more of an issue with theinset_axes() function rather than theGeoAxes class.

Full Stack Trace >
---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)File \personalpath\to\env\site-packages\IPython\core\formatters.py:402,inBaseFormatter.__call__(self,obj)400pass401else:-->402returnprinter(obj)403# Finally look for special method names404method=get_real_method(obj,self.print_method)File \personalpath\to\env\site-packages\IPython\core\pylabtools.py:170,inprint_figure(fig,fmt,bbox_inches,base64,**kwargs)167frommatplotlib.backend_basesimportFigureCanvasBase168FigureCanvasBase(fig)-->170fig.canvas.print_figure(bytes_io,**kw)171data=bytes_io.getvalue()172iffmt=='svg':File \personalpath\to\env\site-packages\matplotlib\backend_bases.py:2155,inFigureCanvasBase.print_figure(self,filename,dpi,facecolor,edgecolor,orientation,format,bbox_inches,pad_inches,bbox_extra_artists,backend,**kwargs)2152# we do this instead of `self.figure.draw_without_rendering`2153# so that we can inject the orientation2154withgetattr(renderer,"_draw_disabled",nullcontext)():->2155self.figure.draw(renderer)2156ifbbox_inches:2157ifbbox_inches=="tight":File \personalpath\to\env\site-packages\matplotlib\artist.py:94,in_finalize_rasterization.<locals>.draw_wrapper(artist,renderer,*args,**kwargs)92 @wraps(draw)93defdraw_wrapper(artist,renderer,*args,**kwargs):--->94result=draw(artist,renderer,*args,**kwargs)95ifrenderer._rasterizing:96renderer.stop_rasterizing()File \personalpath\to\env\site-packages\matplotlib\artist.py:71,inallow_rasterization.<locals>.draw_wrapper(artist,renderer)68ifartist.get_agg_filter()isnotNone:69renderer.start_filter()--->71returndraw(artist,renderer)72finally:73ifartist.get_agg_filter()isnotNone:File \personalpath\to\env\site-packages\matplotlib\figure.py:3257,inFigure.draw(self,renderer)3254# ValueError can occur when resizing a window.3256self.patch.draw(renderer)->3257mimage._draw_list_compositing_images(3258renderer,self,artists,self.suppressComposite)3260renderer.close_group('figure')3261finally:File \personalpath\to\env\site-packages\matplotlib\image.py:134,in_draw_list_compositing_images(renderer,parent,artists,suppress_composite)132ifnot_compositeornothas_images:133forainartists:-->134a.draw(renderer)135else:136# Composite any adjacent images together137image_group= []File \personalpath\to\env\site-packages\matplotlib\artist.py:71,inallow_rasterization.<locals>.draw_wrapper(artist,renderer)68ifartist.get_agg_filter()isnotNone:69renderer.start_filter()--->71returndraw(artist,renderer)72finally:73ifartist.get_agg_filter()isnotNone:File \personalpath\to\env\site-packages\cartopy\mpl\geoaxes.py:524,inGeoAxes.draw(self,renderer,**kwargs)519self.imshow(img,extent=extent,origin=origin,520transform=factory.crs,*factory_args[1:],521**factory_kwargs)522self._done_img_factory=True-->524returnsuper().draw(renderer=renderer,**kwargs)File \personalpath\to\env\site-packages\matplotlib\artist.py:71,inallow_rasterization.<locals>.draw_wrapper(artist,renderer)68ifartist.get_agg_filter()isnotNone:69renderer.start_filter()--->71returndraw(artist,renderer)72finally:73ifartist.get_agg_filter()isnotNone:File \personalpath\to\env\site-packages\matplotlib\axes\_base.py:3210,in_AxesBase.draw(self,renderer)3207ifartists_rasterized:3208_draw_rasterized(self.get_figure(root=True),artists_rasterized,renderer)->3210mimage._draw_list_compositing_images(3211renderer,self,artists,self.get_figure(root=True).suppressComposite)3213renderer.close_group('axes')3214self.stale=FalseFile \personalpath\to\env\site-packages\matplotlib\image.py:134,in_draw_list_compositing_images(renderer,parent,artists,suppress_composite)132ifnot_compositeornothas_images:133forainartists:-->134a.draw(renderer)135else:136# Composite any adjacent images together137image_group= []File \personalpath\to\env\site-packages\matplotlib\artist.py:38,in_prevent_rasterization.<locals>.draw_wrapper(artist,renderer,*args,**kwargs)35renderer.stop_rasterizing()36renderer._rasterizing=False--->38returndraw(artist,renderer,*args,**kwargs)File \personalpath\to\env\site-packages\matplotlib\inset.py:230,inInsetIndicator.draw(self,renderer)226conn_same_style= []228# Figure out which connectors have the same style as the box, so should229# be drawn as a single path.-->230forconninself.connectorsor []:231ifconn.get_visible():232drawn=FalseFile \personalpath\to\env\site-packages\matplotlib\inset.py:221,inInsetIndicator.connectors(self)219ifself._auto_update_bounds:220self._rectangle.set_bounds(self._bounds_from_inset_ax())-->221self._update_connectors()222returntuple(self._connectors)File \personalpath\to\env\site-packages\matplotlib\inset.py:192,inInsetIndicator._update_connectors(self)189pos=self._inset_ax.get_position()190bboxins=pos.transformed(self.get_figure(root=False).transSubfigure)191rectbbox=transforms.Bbox.from_bounds(x,y,width,height).transformed(-->192self._rectangle.get_transform())193x0=rectbbox.x0<bboxins.x0194x1=rectbbox.x1<bboxins.x1File \personalpath\to\env\site-packages\matplotlib\patches.py:309,inPatch.get_transform(self)307defget_transform(self):308"""Return the `~.transforms.Transform` applied to the `Patch`."""-->309returnself.get_patch_transform()+artist.Artist.get_transform(self)File \personalpath\to\env\site-packages\matplotlib\artist.py:454,inArtist.get_transform(self)451self._transform=IdentityTransform()452elif (notisinstance(self._transform,Transform)453andhasattr(self._transform,'_as_mpl_transform')):-->454self._transform=self._transform._as_mpl_transform(self.axes)455returnself._transformFile \personalpath\to\env\site-packages\cartopy\crs.py:267,inCRS._as_mpl_transform(self,axes)265importcartopy.mpl.geoaxesasgeoaxes266ifnotisinstance(axes,geoaxes.GeoAxes):-->267raiseValueError(268'Axes should be an instance of GeoAxes, got %s'%type(axes)269     )270return (271geoaxes.InterProjectionTransform(self,axes.projection)+272axes.transData273 )ValueError:AxesshouldbeaninstanceofGeoAxes,got<class'NoneType'>

Operating system

No response

Matplotlib Version

3.10.1

Matplotlib Backend

No response

Python version

3.12.9

Jupyter version

No response

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp