Is there a way to improve the rendering of this interactive matplotlib/cartopy script ?
Please install first ipympl https://github.com/matplotlib/ipympl
I haven't found how to change the central longitude and latitude without instantiate a new figure.
This script is missing fluidity when clicking with left mouse button and choose the new center of the projection. I am looking for a trackball behaviour as in https://threejs.org/examples/misc_controls_trackball.
Any help/suggestion is welcomed.
%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()