Plotting utilities and functions¶
The package uses a few utility classes and functions to make consistent plotting easy thoughout the package. This reference page documents the lower-level utilities used to make this happen.
Note
The built-in routines to plot Section
and Plan
objects are not documented here, look for documentation on those high-level methods in their respective module documentation.
The functions are defined in deltametrics.plot
.
Default styling¶
By default, each variable receives a set of styling definitions. The default parameters of each styling variable are defined below:

Plotting utility objects¶
|
Variable styling and information. |
|
A default set of properties for variables. |
Plotting utility functions¶
-
deltametrics.plot.
append_colorbar
(ci, ax, size=2)¶ Append a colorbar, consistently placed.
Adjusts some parameters of the parent axes as well.
- Parameters
ci (matplotlib.pyplot.pcolormesh, matplotlib.pyplot.ImageAxes) – The colored object generated via matplotlib that the colormap should be stolen from.
ax (matplotlib.Axes) – The instance of axes to place the colorbar next to.
adjust (
bool
) – Whether to adjust some minor attributes of the parent axis, for presentation.
- Returns
cb – The colorbar instance created.
- Return type
matplotlib.colorbar instance.
-
deltametrics.plot.
get_display_arrays
(VarInst, data=None)¶ Get arrays for display of Variables.
Function takes as argument a VariableInstance from a Section or Planform and an optional
data
argument, which specifies the data type to return, and gives back arrays of 1) data, 2) display x-coordinates and 3) display y-coordinates.- Parameters
VarInst (
BaseSectionVariable
subclass) – The Variable instance to visualize. May be any subclass ofBaseSectionVariable
orBasePlanformVariable
.data (
str
, optional) – The type of data to visualize. Supported options are ‘spacetime’, ‘preserved’, and ‘stratigraphy’. Default is to display full spacetime plot for variable generated from a DataCube, and stratigraphy for a StratigraphyCube variable. Note that variables sourced from a StratigraphyCube do not support the spacetime or preserved options, and a variable from DataCube will only support stratigraphy if the Cube has computed “quick” stratigraphy.
- Returns
data, X, Y – Three matching-size ndarray representing the 1) data, 2) display x-coordinates and 3) display y-coordinates.
- Return type
ndarray
-
deltametrics.plot.
get_display_lines
(VarInst, data=None)¶ Get lines for display of Variables.
Function takes as argument a VariableInstance from a Section or Planform and an optional
data
argument, which specifies the data type to return, and gives back data and line segments for display.- Parameters
VarInst (
BaseSectionVariable
subclass) – The Variable instance to visualize. May be any subclass ofBaseSectionVariable
orBasePlanformVariable
.data (
str
, optional) – The type of data to visualize. Supported options are ‘spacetime’, ‘preserved’, and ‘stratigraphy’. Default is to display full spacetime plot for variable generated from a DataCube. and stratigraphy for a StratigraphyCube variable. Variables from DataCube will only support stratigraphy if the Cube has computed “quick” stratigraphy.note:: (.) – Not currently implemented for variables from the StratigraphyCube.
- Returns
vals, segments – An off-by-one sized array of data values (vals) to color the line segments (segments). The segments are organized along the 0th dimension of the array.
- Return type
ndarray
-
deltametrics.plot.
get_display_limits
(VarInst, data=None)¶ Get limits to resize the display of Variables.
Function takes as argument a VariableInstance from a Section or Planform and an optional
data
argument, which specifies how to determine the limits to return.- Parameters
VarInst (
BaseSectionVariable
subclass) – The Variable instance to visualize. May be any subclass ofBaseSectionVariable
orBasePlanformVariable
.data (
str
, optional) – The type of data to compute limits for. Typically this will be the same value used with eitherget_display_arrays
orget_display_lines
. Supported options are ‘spacetime’, ‘preserved’, and ‘stratigraphy’.
- Returns
xmin, xmax, ymin, ymax – Values to use as limits on a plot. Use with, for example,
ax.set_xlim((xmin, xmax))
.- Return type
float
-
deltametrics.plot.
_fill_steps
(where, x=1, y=1, y0=0, **kwargs)¶ Fill rectangles where the boolean indicates
True
.Creates an
x
byy
matplotlib.patches.Rectangle
at each index where the index i in booleanwhere
indicates, with the lower left of the patch at (i,y0
).This utility function is utilized internally. Most often, it is used to highlight where time has been preserved (or eliminated) in a timeseries of data. For example, see
show_one_dimensional_trajectory_to_strata
.- Parameters
where (
ndarray
) – Boolean numpy ndarray indicating which locations to create a patch at.x (
float
) – The x-direction width of the Rectangles.y (
float
) – The y-direction height of the Rectangles.y0 (
float
) – The y-direction origin (i.e., lower-left y-value) of the Rectangles.**kwargs – Additional matplotlib keyword arguments passed to the Rectangle instantiation. This is where you can set most matplotlib **kwargs (e.g., color, edgecolor).
- Returns
pc – Collection of Rectangle Patch objects.
- Return type
matplotlib.patches.PatchCollection
-
deltametrics.plot.
_scale_lightness
(rgb, scale_l)¶ Utility to scale the lightness of some color.
Make a color perceptually lighter or darker. Adapted from https://stackoverflow.com/a/60562502/4038393.
- Parameters
rgb (
tuple
) – A three element tuple of the RGB values for the color.scale_l (
float
) – The scale factor, relative to a value of 1. A value of 1 performs no scaling, and values less than 1 darken the color, whereas values greater than 1 brighten the color.
- Returns
scaled – Scaled color RGB tuple.
- Return type
tuple
Example
DeltaMetrics plot routines¶
1d elevation to stratigraphy. |
|
|
Show multiple histograms, including as sets. |
DeltaMetrics colormaps¶
-
deltametrics.plot.
cartographic_colormap
(H_SL=0.0, h=4.5, n=1.0)¶ Colormap for an elevation map style.
- Parameters
H_SL (
float
, optional) – Sea level for the colormap. This is the break-point between blues and greens. Default value is 0.0.h (
float
, optional) – Channel depth for the colormap. This is some characteristic below sea-level relief for the colormap to extend to through the range of blues. Default value is 4.5.n (
float
, optional) – Surface topography relief for the colormap. This is some characteristic above sea-level relief for the colormap to extend to through the range of greens. Default value is 1.0.
- Returns
delta (
matplotib.colors.ListedColormap
) – The colormap object, which can then be used by other matplotlib plotting routines (see examples below).norm (
matplotib.colors.BoundaryNorm
) – The color normalization object, which can then be used by other matplotlib plotting routines (see examples below).
Examples
To display with default depth and relief parameters (left) and with adjust parameters to highlight depth variability (right):
rcm8cube = dm.sample_data.cube.rcm8() cmap0, norm0 = dm.plot.cartographic_colormap(H_SL=0) cmap1, norm1 = dm.plot.cartographic_colormap(H_SL=0, h=5, n=0.5) fig, ax = plt.subplots(1, 2, figsize=(10, 4)) im0 = ax[0].imshow(rcm8cube['eta'][-1, ...], origin='lower', cmap=cmap0, norm=norm0) cb0 = dm.plot.append_colorbar(im0, ax[0]) im1 = ax[1].imshow(rcm8cube['eta'][-1, ...], origin='lower', cmap=cmap1, norm=norm1) cb1 = dm.plot.append_colorbar(im1, ax[1]) plt.show()
-
deltametrics.plot.
aerial_colormap
()¶ Colormap for a pesudorealistic looking aerial shot.
Warning
Not implemented.