如何以交互方式更改 cartopy 投影的中心?

PBr*_*ann 6 interactive projection matplotlib cartopy

有没有办法改进这个交互式 matplotlib/cartopy 脚本的渲染?

请先安装 ipympl https://github.com/matplotlib/ipympl

我还没有找到如何在不实例化新图形的情况下更改中心经度和纬度。

当单击鼠标左键并选择新的投影中心时,此脚本缺乏流动性。我正在寻找https://twojs.org/examples/misc_controls_trackball中的轨迹球行为。

欢迎任何帮助/建议。

%matplotlib widget

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

fig = plt.figure(figsize=(10,6), layout='constrained')

proj0 = ccrs.PlateCarree()
proj1 = ccrs.Orthographic(0, 80)

ax1 = fig.add_subplot(1, 1, 1, projection=proj1)
ax1.coastlines()
ax1.gridlines(xlocs=np.arange(-180,180,10), ylocs=np.arange(-80,90,10))
ax1.set_global()

def onpress(event):
    global proj1
    if event.button == 1:
        lon, lat = proj0.transform_point(event.xdata, event.ydata, src_crs=proj1)
        proj1 = ccrs.Orthographic(lon, lat)
        ax1 = fig.add_subplot(1, 1, 1, projection=proj1)
        ax1.coastlines()
        ax1.gridlines(xlocs=np.arange(-180,180,10), ylocs=np.arange(-80,90,10))
        ax1.set_global()
        plt.draw()

fig.canvas.mpl_connect('button_press_event', onpress)

plt.show()

Run Code Online (Sandbox Code Playgroud)

在此输入图像描述