Код: Выделить всё
bbox_inches='tight'
from matplotlib.pyplot import axes, figure
from cartopy.crs import Projection, PlateCarree
class WorldMapAnimator:
def __init__(
self, projection: Projection = PlateCarree(), n_frames: int = 3):
self._projection = projection
self._n_frames = n_frames
@staticmethod
def get_rectangle_for_full_plot():
"""Emulating a public static const"""
rectangle_for_full_plot = [0, 0, 1, 1]
return rectangle_for_full_plot
def animate(self):
self._plot_initial_frame()
for frame in range(self._n_frames):
self._update_frame(frame)
def _plot_initial_frame(self):
self._fig = figure()
# IMPORTANT: The axes must have this type of rectangle configuration
self._ax = axes(
self.get_rectangle_for_full_plot(),
projection=self._projection)
self._ax.coastlines()
def _update_frame(self):
return
class PerlinNoiseAnimator(WorldMapAnimator):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def _plot_initial_frame(self):
# IMPORTANT: here I am modifying a member of the parent class
# and also "soft" requiring the user to call super otherwise they
# won't get expected behavior...
super()._plot_initial_frame()
self._ax.pcolormesh(...) # TODO: write some perlin noise to worldmap
return
def _update_frame(self):
# do something to update the map with new perlin noise here
return
Подробнее здесь: https://stackoverflow.com/questions/796 ... ch-and-enf