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:
abstract add_features()[source]
abstract add_gridlines()[source]
add_land(**kwargs)[source]

Add land feature to the GeoAxes.

Parameters:

kwargs (dict) – Keyword arguments to be passed to the add_feature() method of GeoAxes.

add_ocean(**kwargs)[source]

Add ocean feature to the GeoAxes.

Parameters:

kwargs (dict) – Keyword arguments to be passed to the add_feature() method of GeoAxes.

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 NorthPolarStereo and SouthPolarStereo projections.

add_coastlines(*args, **kwargs)[source]

Add coastlines to the GeoAxes.

Parameters:
add_features(gridlines=True, ruler=True, **kwargs)[source]

Apply various features to the plot.

Parameters:
  • gridlines (bool, optional) – Whether to add gridlines. Defaults to True.

  • ruler (bool, optional) – Whether to add a ruler. Defaults to True.

  • **kwargs – Additional keyword arguments for customization.

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:

cartopy.mpl.gridliner.Gridliner

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 of GeoAxes.

add_ocean(**kwargs)[source]

Add ocean feature to the GeoAxes.

Parameters:

kwargs (dict) – Keyword arguments to be passed to the add_feature() method of GeoAxes.

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.

make_circular()[source]

Make the plot boundary circular.

rotate_lat_labels(target_lon=118, orig_lon=150)[source]

Move the latitude labels to another longitude.

Parameters:
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.

property lat_limits[source]
Get and set the latitude limits for the plot.
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.GeoAxes object.

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()
my_code_base.plot.maps.set_circular_boundary(ax)[source]

Compute a circle in axes coordinates, which we can use as a boundary for the map. We can pan/zoom as much as we like – the boundary will be permanently circular.