您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何更改现有轴的matplotlib子图投影?

如何更改现有轴的matplotlib子图投影?

您不能更改现有轴的投影,原因如下。但是,解决您的基本问题的方法只是使用此处的matplotlib文档中描述的subplot_kw参数。例如,如果您希望所有子图具有投影,则可以执行plt.subplots()cartopy.crs.PlateCarree

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

# Create a grid of plots
fig, (ax1, ax2) = plt.subplots(ncols=2, subplot_kw={'projection': ccrs.PlateCarree()})

关于实际问题,在创建轴集时指定投影将确定您获得的轴类,每种投影类型都不同。例如

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

ax1 = plt.subplot(311)
ax2 = plt.subplot(312, projection='polar')
ax3 = plt.subplot(313, projection=ccrs.PlateCarree())

print(type(ax1))
print(type(ax2))
print(type(ax3))

代码将打印以下内容

<class 'matplotlib.axes._subplots.Axessubplot'>
<class 'matplotlib.axes._subplots.PolarAxessubplot'>
<class 'cartopy.mpl.geoaxes.GeoAxessubplot'>

注意每个轴实际上是一个不同类的实例。

其他 2022/1/1 18:31:15 有432人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶