简体   繁体   English

同一张图上的正常投影和cartopy投影如何处理好?

[英]How to deal well with normal and cartopy projection on the same figure?

I want to produce this kind of figure, taken from Sallee et al.我想制作这种图,取自 Sallee 等人。 (2021) directly from Python if it is possible : (2021) 如果可能的话,直接从 Python 获取:

图目标

There is a Cartopy projection cartopy.crs.Robinson(central_longitude=0, globe=None) in the main subplot and at the right of it something close to a density function (over the latitudes) of my value on the Cartopy projection.在主子图中有一个 Cartopy 投影cartopy.crs.Robinson(central_longitude=0, globe=None) ,在它的右侧有一个接近我在 Cartopy 投影上的值的密度函数(在纬度上)的东西。 Managing the labels with Robinson projection is not convenient for me, whereas with cartopy.crs.PlateCarree(central_longitude=0.0, globe=None) I did not have any issues labelling axis.使用 Robinson 投影管理标签对我来说并不方便,而使用cartopy.crs.PlateCarree(central_longitude=0.0, globe=None)标记轴没有任何问题。

This is the most related topics ( combination of normal and cartopy subplots within the same figure ) that I have founded on stack for now but that doesn't ring any bell since my goal plot is a bit more complicated (size of the colorbar above the Robinson projection, two dashed lines to link the subplots, labelling longitudes and latitudes).这是我目前在堆栈上建立的最相关的主题( 同一图中的普通子图和 cartopy 子图的组合),但由于我的目标图有点复杂(颜色条上方的大小罗宾逊投影,两条虚线连接子图,标注经度和纬度)。

Thank you !谢谢 !

Is there anything specific that you didn't manage to create?有什么具体的东西你没有设法创造吗? Most of what you ask for is readily available from Cartopy/Matplotlib.您要求的大部分内容都可以从 Cartopy/Matplotlib 中轻松获得。

Additional annotation, like the inset zoom lines are possible with Matplotlib, see for example:附加注释,如使用 Matplotlib 可以插入缩放线,例如:
https://matplotlib.org/stable/gallery/subplots_axes_and_figures/zoom_inset_axes.html https://matplotlib.org/stable/gallery/subplots_axes_and_figures/zoom_inset_axes.html

But I personally would avoid that and simply align the axes to make sure they share the same latitude.但我个人会避免这种情况,只需对齐轴以确保它们共享相同的纬度。 That's probably more intuitive for users trying to interpret the data.对于试图解释数据的用户来说,这可能更直观。

A quick example with some random data:一个带有一些随机数据的简单示例:

lats = np.linspace(90-6, -90+6, 15)
data = np.random.randn(15, 32)

proj = ccrs.Robinson(central_longitude=0, globe=None)

fig = plt.figure(figsize=(11, 5), dpi=86, facecolor="w")
spec = fig.add_gridspec(9, 5)

ax1 = fig.add_subplot(spec[1:, :4], projection=proj)
im = ax1.imshow(
    data, cmap="Blues", vmin=-3, vmax=3,
    extent=[-180, 180,90,-90], transform=ccrs.PlateCarree())

cax = fig.add_subplot(spec[0, 1:-2])
cb1 = fig.colorbar(im, cax=cax, orientation="horizontal")
cax.set_title("Something [-]")
cax.xaxis.set_ticks_position('top')

grd = ax1.gridlines(
    draw_labels=True, 
    xlocs=range(-180, 181, 90), 
    ylocs=range(-60, 61, 30), 
    color='k',
)
grd.top_labels = False

ax1.add_feature(cfeature.LAND, facecolor="#eeeeee", zorder=99)


ax2 = fig.add_subplot(spec[1:, -1])
ax2.plot(data.mean(axis=1), lats)
ax2.axvline(0, color="k", lw=1)
ax2.set_xlim(-0.5, 0.5)
ax2.set_yticks(range(-60, 61, 30))
ax2.yaxis.set_label_position("right")
ax2.yaxis.tick_right()
ax2.grid(axis="y")
ax2.set_ylabel("Latitude [deg]")

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM