Wie ändere ich die matplotlib ist Nebenhandlung Projektion einer vorhandenen Achse?

Ich versuche zu konstruieren, die eine einfache Funktion, die eine Nebenhandlung Instanz (matplotlib.axes._subplots.AxesSubplot) und verwandelt seine Projektion auf eine andere Projektion, zum Beispiel, einer der cartopy.crs.CRS Projektionen.

Die Idee sieht in etwa so

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

def make_ax_map(ax, projection=ccrs.PlateCarree()):
    # set ax projection to the specified projection
    ...
    # other fancy formatting
    ax2.coastlines()
    ...

# Create a grid of plots
fig, (ax1, ax2) = plt.subplots(ncols=2)
# the first subplot remains unchanged
ax1.plot(np.random.rand(10))
# the second one gets another projection
make_ax_map(ax2)

Natürlich, kann ich einfach fig.add_subplot() Funktion:

fig = plt.figure(figsize=(10,5))
ax1 = fig.add_subplot(121)
ax1.plot(np.random.rand(10))

ax2 = fig.add_subplot(122,projection=ccrs.PlateCarree())
ax2.coastlines()

aber ich Frage mich, ob es eine richtige matplotlib Methode zum ändern einer Nebenhandlung Achse Projektion nach es definiert wurde. Lesen matplotlib API nicht helfen, leider.

Schreibe einen Kommentar