glidertools.plot.plot_functions

class glidertools.plot.plot_functions

Plot data (gridded or not) as a section and more.

This function provides several options to plot data as a section. The default action when called is to plot data as a pcolormesh section.

See the individual method help for more information about each plotting method.

Parameters:
  • args (array_like) –
    • same length x, y, z. Will be gridded with depth of 1 meter.
    • x(m), y(n), z(n, m) arrays
    • z DataFrame where indicies are depth and columns are dives
    • z DataArray where dim0 is dives and dim1 is depth, or
      contains information about time and depth axes
  • kwargs (key-value pairs) –
    • ax - give an axes to the plotting function
    • robust - use the 0.5 and 99.5 percentile to set color limits
    • gridding_dz - gridding depth [default 1]
__init__()

Initialize self. See help(type(self)) for accurate signature.

Methods

bin_size(depth[, bins, ax, add_colorbar]) Plots a 2D histogram of the depth sampling frequency.
contourf(*args, **kwargs) Plot a section plot of the dives with x-time and y-depth and z-variable.
pcolormesh(*args, **kwargs) Plot a section plot of the dives with x-time and y-depth and z-variable.
save_figures_to_pdf(fig_list, pdf_name, …) Saves a list of figure objects to a pdf.
scatter(x, y, z[, ax, robust]) Plot a scatter section plot of a small dataset (< 10 000 obs)
section3D(dives, depth, x, y, variable[, …]) Returns an interactive 3D plot in an HTML page.
static bin_size(depth, bins=None, ax=None, add_colorbar=True, **hist_kwargs)

Plots a 2D histogram of the depth sampling frequency.

Profiling gliders will often sample at a lower frequency at depth to conserve battery. It is useful to know this frequency if you’d like to make more informed decisions about binning the data.

Parameters:
  • depth (array, dtype=float, shape=[n, ]) – the head-to-tail concatenated depth readings
  • bins ([array, array]) – a user defined set of delta depth and depth bins. If unspecified then these bins are automatically chosen.
  • hist_kwargs (key-value pairs) – passed to the 2D histogram function.
Returns:

Return type:

axes

static contourf(*args, **kwargs)

Plot a section plot of the dives with x-time and y-depth and z-variable. The data can be linearly interpolated to fill missing depth values. The number of points to interpolate can be set with interpolate_dist.

Parameters:
  • args
    • same length x, y, z. Will be gridded with depth of 1 meter.
    • x(m), y(n), z(n, m) arrays
    • z DataFrame where indicies are depth and columns are dives
    • z DataArray where dim0 is dives and dim1 is depth
  • kwargs
    • ax : give an axes to the plotting function
    • robust : use the 0.5 and 99.5 percentile to set color limits
    • gridding_dz : gridding depth [default 1]
    • can also be anything that gets passed to plt.pcolormesh.
Returns:

Return type:

axes

static pcolormesh(*args, **kwargs)

Plot a section plot of the dives with x-time and y-depth and z-variable. The data can be linearly interpolated to fill missing depth values. The number of points to interpolate can be set with interpolate_dist.

Parameters:
  • args (array_like) –
    • same length x, y, z. Will be gridded with depth of 1 meter.
    • x(m), y(n), z(n, m) arrays
    • z DataFrame where indicies are depth and columns are dives
    • z DataArray where dim0 is dives and dim1 is depth
  • kwargs (key-value pairs) –
    • ax - give an axes to the plotting function
    • robust - use the 0.5 and 99.5 percentile to set color limits
    • gridding_dz - gridding depth [default 1]
static save_figures_to_pdf(fig_list, pdf_name, **savefig_kwargs)

Saves a list of figure objects to a pdf.

This function is useful if you’d like to create automatic QC reports in PDF format with a plot per page.

Parameters:
  • fig_list (list) – list of figure objects
  • pdf_name (str) – path to save pdf to.
  • savefig_kwargs (key-value pairs passed to Figure.savefig) –
static scatter(x, y, z, ax=None, robust=False, **kwargs)

Plot a scatter section plot of a small dataset (< 10 000 obs)

Parameters:
  • x (array, dtype=float, shape=[n, ]) – continuous horizontal variable (e.g. time, lat, lon)
  • y (array, dtype=float, shape=[n, ]) – continous vertical variable (e.g. depth, density)
  • z (array, dtype=float, shape=[n, ]) – ungridded data variable
  • ax (matplotlib.axes) – a predefined set of axes to draw on
  • robust (bool=False) – if True, uses the 0.5 and 99.5 percentile to set color limits
  • kwargs (any key:values pair that gets passed to plt.pcolormesh.) –
Returns:

Return type:

axes

Raises:

will ask if you want to continue if more than 10000 points

static section3D(dives, depth, x, y, variable, zmin=-1000, zmax=1, vmin=None, vmax=None, cmap=None, aspect_ratio_x=1.5, return_plot=True)

Returns an interactive 3D plot in an HTML page.

Parameters:
  • dives (array, dtype=float, shape=[n, ]) – timeseries of dive number (or can be pseudo discrete time)
  • depth (array, dtype=float, shape=[n, ]) – head-to-tail concatenated depth readings
  • x (array, dtype=float, shape=[n, ]) – the x-coordinate used in the plot (e.g. longitude, time)
  • y (array, dtype=float, shape=[n, ]) – the y-coordinate used in the plot (e.g. latitude, time)
  • variable (array, dtype=float, shape=[n, ]) – the variable to grid and plot (e.g. temperature salinity)
  • zmin (int=-1000) – lower depth limit for the depth axis
  • zmax (int=1) – upper depth limit for the depth axis
  • vmin (float=None) – lower color limit of variable. Defaults to 1st percentile
  • vmax (float=None) – upper color limit of variable. Defaults to 99th percentile
  • cmap (cm.colormap=cm.Spectral_r) – colorbar used in the plot
  • aspect_ratio (float=1.5) – the ratio of the plot [1.5] (best to use trail and error)
Returns:

Return type:

a plotly figure object that can be adjusted if needed

Example

>>> fig = gt.plot.section3D(df.dives, df.ctd_depth, df.longitude,
                            df.latitude, df.temperature)