my_code_base.plot.maps¶
Module Contents¶
- class my_code_base.plot.maps.GeoAxesAccessor(ax)[source]¶
Helper class that provides a standard way to create an ABC using inheritance.
- add_coastlines(*args, **kwargs)[source]¶
Add coastlines to the
GeoAxes.- Parameters:
args (list) – Arguments to be passed to the
coastlines()method ofGeoAxes.kwargs (dict) – Keyword arguments to be passed to the
coastlines()method ofGeoAxes.
- add_land(**kwargs)[source]¶
Add land feature to the
GeoAxes.- Parameters:
kwargs (dict) – Keyword arguments to be passed to the
add_feature()method ofGeoAxes.
- add_ocean(**kwargs)[source]¶
Add ocean feature to the
GeoAxes.- Parameters:
kwargs (dict) – Keyword arguments to be passed to the
add_feature()method ofGeoAxes.
- set_extent(extent, crs=cartopy.crs.PlateCarree())[source]¶
Set the extent of the
GeoAxes.- Parameters:
extent (tuple) – The extent of the
GeoAxes. It should be a tuple of the form (xmin, xmax, ymin, ymax).crs (cartopy.crs) – The coordinate reference system in which the extent is expressed. Default is
PlateCarree.
- class my_code_base.plot.maps.StereographicAxisAccessor(ax)[source]¶
An accessor to handle features and finishing of stereographic plots produced with cartopy. Can handle both
NorthPolarStereoandSouthPolarStereoprojections.- add_coastlines(*args, **kwargs)[source]¶
Add coastlines to the
GeoAxes.- Parameters:
args (list) – Arguments to be passed to the
coastlines()method ofGeoAxes.kwargs (dict) – Keyword arguments to be passed to the
coastlines()method ofGeoAxes.
- add_features(gridlines=True, ruler=True, **kwargs)[source]¶
Apply various features to the plot.
- Parameters:
- Return type:
None
Notes
This method applies the following features to the plot:
add ocean
add land
add coastlines
add ruler
make the boundary circular
add gridlines
<Figure size 640x480 with 1 Axes>
- add_gridlines(**kwargs)[source]¶
Add gridlines to the plot.
- Parameters:
**kwargs (dict) – Additional keyword arguments for customization.
- Returns:
The gridliner object.
- Return type:
Notes
This method adds gridlines to the plot using the specified keyword arguments for customization. The default values for the keyword arguments are:
‘zorder’: 1
‘linestyle’: ‘-’
‘linewidth’: 0.5
‘color’: ‘gray’
‘alpha’: 0.7
The gridlines are added based on the latitude limits of the plot. The latitude grid spacing is set to 10 degrees. The longitude grid spacing is determined by the latitude grid spacing and the x_spacing_factor. The gridlines are created using the gridlines method of the geo_axes object. The draw_labels argument is set to True for the first set of gridlines and False for the second set.
- add_land(**kwargs)[source]¶
Add land feature to the
GeoAxes.- Parameters:
kwargs (dict) – Keyword arguments to be passed to the
add_feature()method ofGeoAxes.
- add_ocean(**kwargs)[source]¶
Add ocean feature to the
GeoAxes.- Parameters:
kwargs (dict) – Keyword arguments to be passed to the
add_feature()method ofGeoAxes.
- add_ruler(**kwargs)[source]¶
Add a circular ruler to the plot.
See
add_circular_ruler()for customization arguments. The ax argument is not needed to be handed over when using the accessor’s method.- Parameters:
kwargs – Additional keyword arguments for customization.
- rotate_lat_labels(target_lon=118, orig_lon=150)[source]¶
Move the latitude labels to another longitude.
- Parameters:
target_lon (int) – The longitude to which the labels should be moved.
orig_lon (int) – The longitude at which the labels are located per default [default: 150].
Source (https://stackoverflow.com/a/66587492/5925453 with minor adaptions.)
- rotate_lon_labels()[source]¶
Rotate the longitude labels of a stereographic plot for better readability and nicer look.
- set_extent(extent, crs=cartopy.crs.PlateCarree())[source]¶
Set the extent of the
GeoAxes.- Parameters:
extent (tuple) – The extent of the
GeoAxes. It should be a tuple of the form (xmin, xmax, ymin, ymax).crs (cartopy.crs) – The coordinate reference system in which the extent is expressed. Default is
PlateCarree.
- my_code_base.plot.maps.add_circular_ruler(ax, segment_length=30, offset=0, primary_color='k', secondary_color='w', width=1)[source]¶
Add a ruler around a polar stereographic plot.
- Parameters:
ax (GeoAxes) – The GeoAxes object to which the ruler should be added
segment_length (int) – The length of each segment in degrees
offset (int) – An optional offset
primary_color (str) – The color of the background ruler segments
secondary_color (str) – The color of the top ruler segments
width (float) – The scaled thickness of the ruler. Defaults to 1/80 of the axes’ width.
- my_code_base.plot.maps.register_geoaxes_accessor(accessor_name)[source]¶
A decorator to register an accessor for a
cartopy.mpl.geoaxes.GeoAxesobject.Example
>>> pytest.skip() >>> @register_geoaxes_accessor("my_accessor") >>> class MyCustomAccessor: >>> def some_method(self): >>> pass >>> >>> ax = plt.subplot(projection=cartopy.crs.NorthPolarStereo()) >>> ax.my_accessor.some_method()