如何在 Matplotlib 中附加轴但不继承轴类型具体来说是 Cartopy 类型

问题描述

我使用 Basemap 进行绘图,它没有引入自己的轴类型,而是进行了一些极端的数学运算来进行地理绘图。这让这个工作:

import matplotlib.pyplot as plt
fig,ax = plt.subplots(); #use instead of fig because it inits an axis too
divider = make_axes_locatable(ax); #prep to add an axis
cax = divider.append_axes('right',size='2.0%',pad=0.15); #make a color bar axis

我更喜欢这个,因为它使新轴保持在原始轴边界内,这使得排列其他子图(通过对它们使用相同的 divider.append_axes(...) 调用)很容易,并确保新的颜色条轴没有'也可以轻松剪掉情节。

但由于 Basemap 已贬值,我正在尝试迁移到 cartopy。不幸的是与 cartopy 类似的代码

import matplotlib.pyplot as plt
import cartopy as cartopy
fig,ax = plt.subplots(); #use instead of fig because it inits an axis too
ax = plt.axes(projection=cartopy.crs.PlateCarree()); #redefine the axis to be a geographical axis
divider = make_axes_locatable(ax); #prep to add an axis
cax = divider.append_axes('right',pad=0.15); #make a color bar axis

给出错误

KeyError: 'map_projection'

由于在 cartopy 下,轴 ax 更改为 cartopy 轴,因此附加轴 cax 也是 cartopy 轴。如果我提供 map_projection=cartopy.crs.PlateCarree() 代码运行,但我不希望它是 cartopy 轴,我希望它是一个颜色条(如果我将它用作颜色条,cartopy 轴会出错)。>

我如何append_axes但不继承 cartopy 轴类型?

此外,我发现使用以下方法还不够好:

import matplotlib.pyplot as plt
import cartopy as cartopy
fig,ax = plt.subplots(); #use instead of fig because it inits an axis too
ax = plt.axes(projection=cartopy.crs.PlateCarree()); #redefine the axis to be a geographical axis
cax = ax.inset_axes((1.02,0.02,1)); #make a color bar axis

但是 cax 不是原始轴边界的一部分,这使得它无法用于排列使用 divider.append_axes() 方法的其他子图,并且颜色条可以剪掉图的边缘,因为它漂浮在“空白”中。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...