Visualize Cactus Data¶
This module provides functions to plot various Cactus data types,
such as 2D RegData
, TimeSeries
.
- postcactus.visualize.adj_limits(var, units=1.0, aspect='equal', axes=None)¶
Set limits of axes to coordinate range of data.
- Parameters
var – Data from which to take coordinate range.
units (float or pair of floats.) – Units for x and y coordinates.
aspect (string or float) – Aspect ratio of axes.
axes (matplotlib.axes instance or None) – Which axes to adjust. Defaults to current axes.
- postcactus.visualize.color_bar(image=None, cax=None, ax=None, label=None, ticks=None, **kwargs)¶
Adds a colorbar with optional label.
- Parameters
image – Object to which the colorbar refers, e.g. the result of imshow.
cax – Existing colorbar axes, see matplotlibs colorbar().
ax – Axes where to insert colorbar axes, see matplotlibs colorbar().
label – Colorbar label.
ticks – location of the ticks.
Unknown keyword arguments are passed to matplotlibs colorbar()
- Returns
Colorbar instance.
- postcactus.visualize.get_color_map(name, over=None, under=None, masked=None)¶
Get color map by name and set special colors for out-of-range values.
- Parameters
name (string) – Name of the colormap.
over (Matplotlib color or None.) – Color for too large values.
under (Matplotlib color or None.) – Color for too large values.
masked (Matplotlib color or None.) – Color for masked values.
- Returns
Matplotlib color map.
- postcactus.visualize.plot_color(var, mask=None, axes=None, vmin=None, vmax=None, units=1.0, cmap=None, interpolation='nearest', bar=False, barlabel=None, barticks=None, barshrink=1, barextend='neither', **kwargs)¶
Makes a 2D color plot of RegData instances.
- Parameters
var (
RegData
instance) – 2D data to plot.mask (
RegData
or numpy array or None) – Optional mask for the plot.axes (matplotlib.axes instance or None) – Which axes to use for the plot. Defaults to current axes.
vmin (float or None) – Minimum value for color scale. Defaults to data minimum.
vmax (float or None) – Maximum value for color scale. Defaults to data maximum.
units (float or pair of floats.) – Units for x and y coordinates.
cmap (Matplotlib colormap) – Colormap to use for the plot.
interpolation (string) – Interpolation method, see matplotlib imshow(). Defaults to nearest point.
bar (bool) – Whether to add a colorbar.
barlabel (string or None) – Label for the colorbar.
barticks (list of floats or None) – Locations of the colorbar ticks. Default: choose automatic.
barshrink (float) – Factor to shrink the colorbar.
barextend (str) – Whether to show the colors for out of range values at the ends of the colorbar.
Unknown keyword arguments are passed to matplotlibs imshow()
- Returns
Image object.
- Return type
matplotlib.image.AxesImage object.
- postcactus.visualize.plot_color_direct(red, green, blue, mask=None, axes=None, vmax=None, units=1.0, interpolation='nearest', **kwargs)¶
Makes a 2D image with color components given by 3 RegData instances.
- Parameters
red (
RegData
instance) – 2D data for red component.green (
RegData
instance) – 2D data for green component.blue (
RegData
instance) – 2D data for blue component.mask (
RegData
or numpy array or None) – Optional mask for the plot.axes (matplotlib.axes instance or None) – Which axes to use for the plot. Defaults to current axes.
vmax (float or None) – Maximum value for color scale. Defaults to data maximum.
units (float or pair of floats.) – Units for x and y coordinates.
interpolation (string) – Interpolation method, see matplotlib imshow(). Defaults to nearest point.
Unknown keyword arguments are passed to matplotlibs imshow()
- postcactus.visualize.plot_contour(var, levels, mask=None, axes=None, units=1.0, labels=False, labelfmt='%g', neg_solid=False, **kwargs)¶
Makes a contour plot of RegData instances.
- Parameters
var (
RegData
instance) – 2D data to plot.levels (list of floats) – Level contours to draw.
mask (
RegData
or numpy array) – Optional mask for the data.axes (matplotlib.axes instance or None) – Which axes to use for the plot. Defaults to current axes.
units (float or pair of floats.) – Units for x and y coordinates.
labels (bool) – If True, add lables to contours.
labelfmt (str or None) – Format string for contour labels.
neg_solid (bool) – Whether to draw negative contours solid or wtih default.
Unknown keyword arguments are passed to matplotlibs contour()
- Returns
Contour lines.
- Return type
QuadContourSet object.
- postcactus.visualize.plot_contourf(var, levels, mask=None, axes=None, units=1.0, **kwargs)¶
Makes a filled contour plot of RegData instances.
- Parameters
var (
RegData
instance) – 2D data to plot.levels (list of floats) – Level contours to draw.
mask (
RegData
or numpy array) – Optional mask for the data.axes (matplotlib.axes instance or None) – Which axes to use for the plot. Defaults to current axes.
units (float or pair of floats.) – Units for x and y coordinates.
Unknown keyword arguments are passed to matplotlibs contour()
- Returns
Contour lines.
- Return type
QuadContourSet object.
- postcactus.visualize.plot_grid_struct(data, units=1.0, axes=None, facecolor=None, edgecolor=None, **kwargs)¶
Plots grid structure of CompData or RegData objects.
- Parameters
data (
RegData
orCompData
) – Data for which to plot the structure.units (float or pair of floats.) – Units for x and y coordinates.
axes (matplotlib.axes instance or None) – Which axes to use for the plot. Defaults to current axes.
edgecolor (list of colors or None) – Which colors to use for the edges of the components on different levels. Will be repeated if shorter than number of refinement levels.
facecolor (list of colors or None) – Like edgecolor, but for the interior of the components.
Unknown keyword arguments are passed to matplotlibs patches.Rectangle()
- postcactus.visualize.plot_integral_curves(vec, mask=None, num_seed=800, seglength=0.1, seed_pos=None, axes=None, units=1.0, **kwargs)¶
Plots integral curves of a vector field. Seed positions are choosen randomly.
- Parameters
vec (pair of callable objects.) – Data to plot. Must be 2D.
num_seed (int) – Desired number of lines.
seglength (float) – Length of lines as fraction of figure size.
seedpos (Nx2 numpy array or None) – Positions where to begin the integral curves or None.
axes (matplotlib.axes instance or None) – Which axes to use for the plot. Defaults to current axes.
units (float or pair of floats.) – Units for x and y coordinates.
Unknown keyword arguments are passed to matplotlibs plot()
- postcactus.visualize.plot_ts(ts, units=1.0, axes=None, **kwargs)¶
Plots a TimeSeries object.
- Parameters
ts (
TimeSeries
instance) – Time series to plot.units (float or pair of floats.) – Units for t and y coordinates.
axes (matplotlib.axes instance or None) – Which axes to use for the plot. Defaults to current axes.
Unknown keyword arguments are passed to matplotlibs plot()
- Returns
Result of matplotlibs plot() function.
- postcactus.visualize.plot_vectors(vec, mask=None, narrows=800, vmax=None, unit=1.0, x0=None, x1=None, axes=None, **kwargs)¶
Plots a vector field. Resamples data to get desired number of arrows.
- Parameters
vec (vector of
RegData
) – Data to plot. Must be 2D.mask (
RegData
or numpy array) – Optional mask for the data.narrows (int) – Desired number of arrows.
vmax (float or None) – Maximum length assumed for scaling vectors.
unit (float) – Unit for both x and y coordinates.
x0 (length-2 float list/array or None) – Sample region lower left coordinate. Default: use data coordinate range.
x1 (length-2 float list/array or None) – Sample region upper right coordinate. Default: use data coordinate range.
axes (matplotlib.axes instance or None) – Which axes to use for the plot. Defaults to current axes.
Unknown keyword arguments are passed to matplotlibs quiver()
- postcactus.visualize.sample_vectors(vec, mask=None, narrows=800, x0=None, x1=None)¶
Samples a vector field for plotting purposes.
- Parameters
vec (2D vector of 2D
RegData
) – Vector to sample.mask (
RegData
or numpy array) – Optional mask for the data.narrows (int) – Desired number of arrows.
x0 (length-2 float list/array or None) – Sample region lower left coordinate. Default: use data coordinate range.
x1 (length-2 float list/array or None) – Sample region upper right coordinate. Default: use data coordinate range.
The results of this function are
- cdlength-2 tuple of lists or arrays
x- and y-coordinates of the samples.
- dlength-2 tuple of lists or arrays
x- and y-components of sampled vectors.
- vmaxfloat
Maximum length of all sampled vectors.
- lfloat
Average distance between sampled vectors.
- Returns
A tuple (cd,d,vmax,l)
- postcactus.visualize.savefig_multi(name, formats, **kwargs)¶
Save current figure in multiple formats.
- Parameters
name (string) – Filename without extension.
formats (string) – Comma-separated list of file formats.
Unknown keyword arguments are passed to matplotlibs savefig()
- postcactus.visualize.set_tick_color(color, axes=None)¶
Set tick color.
- Parameters
color – Tick color.
axes – Axes for which to change the tick color or None for current axes.