Documentation page for basemap_utils.py

Basemap 2D plotting functions and classes.

Author: guangzhi XU (xugzhi1987@gmail.com) Update time: 2021-02-14 13:42:31.

class basemap_utils.Plot2Basemap(*args: Any, **kwargs: Any)

2D geographical plotting class, using basemap

__init__(var, method, xarray, yarray, ax=None, title=None, label_axes=True, axes_grid=False, legend=None, legend_ori=None, clean=False, fontsize=None, projection=None, fill_color=None, fix_aspect=False, isdrawcoastlines=True, isdrawcountries=True, isdrawcontinents=False, isdrawrivers=False, isfillcontinents=False, bmap=None)

2D geographical plotting class, using basemap

Parameters
  • var (ndarray) – input data to plot. Determines what to plot. Mush have dimensions >= 2. For data with rank>2, take the slab from the last 2 dimensions.

  • method (PlotMethod) – plotting method. Determines how to plot. Could be Isofill, Isoline, Boxfill, Quiver, Shading, Hatch, GIS.

  • xarray (1darray or None) – array to use as the x-coordinates. If None, use the indices of the last dimension: np.arange(slab.shape[-1]).

  • yarray (1darray or None) – array to use as the y-coordinates. If None, use the indices of the 2nd last dimension: np.arange(slab.shape[-2]).

Keyword Arguments
  • ax (matplotlib axis or None) – axis obj. Determines where to plot. If None, create a new.

  • title (str or None) – text as the figure title if <ax> is the single plot in the figure. If None, automatically get an alphabetic subtitle if <ax> is a subplot, e.g. ‘(a)’ for the 1st subplot, ‘(d)’ for the 4th one. If str and <ax> is a subplot, prepend <title> with the alphabetic index. One can force overriding the alphabetic index by giving a title str in the format of ‘(x) xxxx’, e.g. ‘(p) subplot-p’.

  • label_axes (bool or 'all' or tuple) – controls axis ticks and ticklabels. If True, don’t exert any inference other than changing the ticklabel fontsize, and let matplotlib put the ticks and ticklabels (i.e. default only left and bottom axes). If False, turn off all ticks and ticklabels. If ‘all’, plot ticks and ticks labels on all 4 sides. If (left, right, top, bottom), specify which side to plot ticks/ticklabels. Each swith is a bool or binary. If None, will set the ticks/ticklabels such that the interior subplots have no ticks/ticklabels, edge subplots have ticks/ticklabels on the outer edges, i.e. similar as the ‘sharex’, ‘sharey’ options. Location of the subplot is determined from return of ax.get_geometry().

  • axes_grid (bool) – whether to add axis grid lines.

  • legend (str or None) – controls whether to share colorbar or not. A colorbar is only plotted for Isofill/Isoline plots. If None, don’t put colorbar. If ‘local’, <ax> has its own colorbar. If ‘global’, all subplots in the figure share a single colorbar, which is created by the 1st subplot in the figure, which is determined from the return of ax.get_geometry().

  • legend_ori (str) – orientation of colorbar. ‘horizontal’ or ‘vertical’.

  • clean (bool) – if False, don’t plot axis ticks/ticklabels, colorbar, axis grid lines or title.

  • fontsize (int) – font size for ticklabels, title, axis labels, colorbar ticklabels.

  • projection (str) – the map projection.

  • fill_color (str or color tuple) – color to use as background color. If data have missings, they will be shown as this color. It is better to use a grey than while to better distinguish missings.

  • fix_aspect (bool) – passed to the constructor of basemap: Basemap(xxx, fix_aspect=fix_aspect).

  • isdrawcoastlines (bool) – whether to draw continent outlines or not.

  • isdrawcountries (bool) – whether to draw contry boundaries or not.

  • isdrawrivers (bool) – whether to draw rivers or not.

  • isfillcontinents (bool) – whether to fill continents or not.

  • bmap (basemap obj or None) – reuse an existing basemap obj if not None.

createBmap()

Create basemap based on data domain

plotAxes()

Plot longitude/latitude ticks and ticklabels

Overwrites parent classes method

plotOthers()

Plot other map information

Plot continents, contries, rivers if needed.

class basemap_utils.Plot2QuiverBasemap(*args: Any, **kwargs: Any)

2D geographical quiver plotting class, using basemap

__init__(u, v, method, xarray, yarray, ax=None, title=None, label_axes=True, axes_grid=False, clean=False, fontsize=None, projection=None, units=None, fill_color='w', curve=False, fix_aspect=False, isdrawcoastlines=True, isdrawcountries=True, isdrawcontinents=False, isdrawrivers=False, isfillcontinents=False, bmap=None)

2D geographical quiver plotting class, using basemap

Parameters
  • u (ndarray) – x- and y-component of velocity to plot. Mush have dimensions >= 2. For data with rank>2, take the slab from the last 2 dimensions.

  • v (ndarray) – x- and y-component of velocity to plot. Mush have dimensions >= 2. For data with rank>2, take the slab from the last 2 dimensions.

  • method (Quiver obj) – quiver plotting method. Determines how to plot the quivers.

  • xarray (1darray or None) – array to use as the x-coordinates. If None, use the indices of the last dimension: np.arange(slab.shape[-1]).

  • yarray (1darray or None) – array to use as the y-coordinates. If None, use the indices of the 2nd last dimension: np.arange(slab.shape[-2]).

Keyword Arguments
  • ax (matplotlib axis or None) – axis obj. Determines where to plot. If None, create a new.

  • title (str or None) – text as the figure title if <ax> is the single plot in the figure. If None, automatically get an alphabetic subtitle if <ax> is a subplot, e.g. ‘(a)’ for the 1st subplot, ‘(d)’ for the 4th one. If str and <ax> is a subplot, prepend <title> with the alphabetic index. One can force overriding the alphabetic index by giving a title str in the format of ‘(x) xxxx’, e.g. ‘(p) subplot-p’.

  • label_axes (bool or 'all' or ((left_y, right_y, top_y, top_y) – (left_x, right_x, top_x, top_x)) or None): controls axis ticks and ticklabels. If True, don’t exert any inference other than changing the ticklabel fontsize, and let matplotlib put the ticks and ticklabels (i.e. default only left and bottom axes). If False, turn off all ticks and ticklabels. If ‘all’, plot ticks and ticks labels on all 4 sides. If ((left_y, right_y, top_y, top_y), (left_x, right_x, top_x, top_x)), specify which side to plot ticks/ticklabels. Each swith is a bool or binary. If None, will set the ticks/ticklabels such that the interior subplots have no ticks/ticklabels, edge subplots have ticks/ticklabels on the outer edges, i.e. similar as the ‘sharex’, ‘sharey’ options. Location of the subplot is determined from return of ax.get_geometry().

  • axes_grid (bool) – whether to add axis grid lines.

  • clean (bool) – if False, don’t plot axis ticks/ticklabels, colorbar, axis grid lines or title.

  • fontsize (int) – font size for ticklabels, title, axis labels, colorbar ticklabels.

  • projection (str) – the map projection.

  • units (str or None) – unit of <u> and <v>. Will be plotted next to the reference vector.

  • fill_color (str or color tuple) – color to use as background color. If data have missings, they will be shown as this color. It is better to use a grey than while to better distinguish missings.

  • curve (bool) – whether to plot quivers as curved vectors. Experimental.

  • fix_aspect (bool) – passed to the constructor of basemap: Basemap(xxx, fix_aspect=fix_aspect).

  • isdrawcoastlines (bool) – whether to draw continent outlines or not.

  • isdrawcountries (bool) – whether to draw contry boundaries or not.

  • isdrawrivers (bool) – whether to draw rivers or not.

  • isfillcontinents (bool) – whether to fill continents or not.

  • bmap (basemap obj or None) – reuse an existing basemap obj if not None.

plot()

Main plotting interface

Calls the core plotting function self._plot(), which handles the 2D plotting using quiver plotting method. Then plots axes, quiverkey and title.

Returns

self.quiver (mappable) – the quiver obj, i.e. return value quiver().

basemap_utils.blueMarble(lat1, lon1, lat2, lon2, fig=None, projection='merc')

Plot bluemarble plot as background.

Parameters
  • lat1 (floats) – low-left corner. Longitude range 0-360

  • lon1 (floats) – low-left corner. Longitude range 0-360

  • lat2 (floats) – upper-right corner.

  • lon2 (floats) – upper-right corner.

Keyword Arguments
  • fig (matplotlib figure or None) – If None, create a new.

  • projection (str) – map projection.

NOTE: due to a bug in basemap, if the plot range is crossing the dateline, need to plot 2 separate plots joining at the dateline.