xyzpy.plot.plotter_matplotlib
#
Functions for plotting datasets nicely.
Module Contents#
Classes#
Functions#
|
Decorate a plotting function to plot a grid of values. |
|
From |
|
Auto version of |
|
From |
|
Auto version of |
|
Dataset histogram. |
|
Auto version of |
|
From |
|
Auto version of |
|
|
|
|
|
|
|
|
|
|
Simple wrapper to handle sequence of arrays as input to e.g. |
|
|
Visualize |
|
Visualize all entries of a tensor, with indices mapped into the plane |
Attributes#
- class xyzpy.plot.plotter_matplotlib.PlotterMatplotlib(ds, x, y, z=None, y_err=None, x_err=None, **kwargs)[source]#
Bases:
xyzpy.plot.core.Plotter
- xyzpy.plot.plotter_matplotlib.mpl_multi_plot(fn)[source]#
Decorate a plotting function to plot a grid of values.
- class xyzpy.plot.plotter_matplotlib.LinePlot(ds, x, y, z=None, *, y_err=None, x_err=None, **kwargs)[source]#
- xyzpy.plot.plotter_matplotlib.lineplot(ds, x, y, z=None, y_err=None, x_err=None, **plot_opts)[source]#
From
ds
plot lines ofy
as a function ofx
, optionally for varyingz
.- Parameters:
ds (xarray.Dataset) – Dataset to plot from.
x (str) – Dimension to plot along the x-axis.
y (str or tuple[str]) – Variable(s) to plot along the y-axis. If tuple, plot each of the variables - instead of
z
.z (str, optional) – Dimension to plot into the page.
y_err (str, optional) – Variable to plot as y-error.
x_err (str, optional) – Variable to plot as x-error.
row (str, optional) – Dimension to vary over as a function of rows.
col (str, optional) – Dimension to vary over as a function of columns.
plot_opts – See
xyzpy.plot.core.PLOTTER_DEFAULTS
.
- xyzpy.plot.plotter_matplotlib.auto_lineplot(x, y_z, **lineplot_opts)[source]#
Auto version of
lineplot()
that accepts array arguments by converting them to aDataset
first.
- xyzpy.plot.plotter_matplotlib._SCATTER_ALT_DEFAULTS = (('legend_handlelength', 0),)#
- xyzpy.plot.plotter_matplotlib.scatter(ds, x, y, z=None, y_err=None, x_err=None, **plot_opts)[source]#
From
ds
plot a scatter ofy
againstx
, optionally for varyingz
.- Parameters:
ds (xarray.Dataset) – Dataset to plot from.
x (str) – Quantity to plot along the x-axis.
y (str or tuple[str]) – Quantity(s) to plot along the y-axis. If tuple, plot each of the variables - instead of
z
.z (str, optional) – Dimension to plot into the page.
y_err (str, optional) – Variable to plot as y-error.
x_err (str, optional) – Variable to plot as x-error.
row (str, optional) – Dimension to vary over as a function of rows.
col (str, optional) – Dimension to vary over as a function of columns.
plot_opts – See
xyzpy.plot.core.PLOTTER_DEFAULTS
.
- xyzpy.plot.plotter_matplotlib.auto_scatter(x, y_z, **scatter_opts)[source]#
Auto version of
scatter()
that accepts array arguments by converting them to aDataset
first.
- xyzpy.plot.plotter_matplotlib._HISTOGRAM_SPECIFIC_OPTIONS#
- xyzpy.plot.plotter_matplotlib._HISTOGRAM_ALT_DEFAULTS#
- xyzpy.plot.plotter_matplotlib.histogram(ds, x, z=None, **plot_opts)[source]#
Dataset histogram.
- Parameters:
ds (xarray.Dataset) – The dataset to plot.
x (str, sequence of str) – The variable(s) to plot the probability density of. If sequence, plot a histogram of each instead of using a
z
coordinate.z (str, optional) – If given, range over this coordinate a plot a histogram for each.
row (str, optional) – Dimension to vary over as a function of rows.
col (str, optional) – Dimension to vary over as a function of columns.
plot_opts – See
xyzpy.plot.core.PLOTTER_DEFAULTS
.
- xyzpy.plot.plotter_matplotlib.auto_histogram(x, **histogram_opts)[source]#
Auto version of
histogram()
that accepts array arguments by converting them to aDataset
first.
- xyzpy.plot.plotter_matplotlib._HEATMAP_ALT_DEFAULTS = (('legend', False), ('colorbar', True), ('colormap', 'inferno'), ('method', 'pcolormesh'),...#
- xyzpy.plot.plotter_matplotlib.heatmap(ds, x, y, z, **kwargs)[source]#
From
ds
plot variablez
as a function ofx
andy
using a 2D heatmap.- Parameters:
ds (xarray.Dataset) – Dataset to plot from.
x (str) – Dimension to plot along the x-axis.
y (str) – Dimension to plot along the y-axis.
z (str, optional) – Variable to plot as colormap.
row (str, optional) – Dimension to vary over as a function of rows.
col (str, optional) – Dimension to vary over as a function of columns.
plot_opts – See
xyzpy.plot.core.PLOTTER_DEFAULTS
.
- xyzpy.plot.plotter_matplotlib.auto_heatmap(x, **heatmap_opts)[source]#
Auto version of
heatmap()
that accepts array arguments by converting them to aDataset
first.
- xyzpy.plot.plotter_matplotlib.setup_fig_ax(nrows=1, ncols=1, facecolor=None, rasterize=False, rasterize_dpi=300, figsize=(5, 5), ax=None, **kwargs)[source]#
- xyzpy.plot.plotter_matplotlib.to_colors(zs, magscale='linear', max_mag=None, alpha_map=True, alpha_pow=1 / 2)[source]#
- xyzpy.plot.plotter_matplotlib.add_visualize_legend(ax, complexobj, max_mag, max_projections=2, auto_pad=0.03, legend_loc='auto', legend_size=0.15, legend_bounds=None, legend_resolution=3)[source]#
- xyzpy.plot.plotter_matplotlib.handle_sequence_of_arrays(f)[source]#
Simple wrapper to handle sequence of arrays as input to e.g.
visualize_tensor
.
- xyzpy.plot.plotter_matplotlib.visualize_matrix(array, max_mag=None, magscale='linear', alpha_map=True, alpha_pow=1 / 2, legend=True, legend_loc='auto', legend_size=0.15, legend_bounds=None, legend_resolution=3, facecolor=None, rasterize=4096, rasterize_dpi=300, figsize=(5, 5), ax=None)[source]#
Visualize
array
as a 2D colormapped image.- Parameters:
array (array_like or Sequence[array_like]) – A 2D (or 1D) array or sequence of arrays to visualize.
max_mag (float, optional) – The maximum magnitude to use for the color mapping. If not provided, the maximum magnitude in the array will be used.
magscale ("linear" or float, optional) – How to scale the magnitude of the array values. If “linear”, then the magnitude is used directly. If a float, then the magnitude is raised to this power before being used, which can help to show variation among small values.
alpha_map (bool, optional) – Whether to map the tensor value magnitudes to pixel alpha.
alpha_pow (float, optional) – The power to raise the magnitude to when mapping to alpha.
legend (bool, optional) – Whether to show a legend (colorbar). If the array has complex dtype then the legend will be a colorwheel.
legend_loc (str or tuple[float], optional) – Where to place the legend. If “auto”, then the legend will be placed outside the plot rectangle, otherwise it should be a tuple of
(x, y)
coordinates in axes space.legend_size (float, optional) – The size of the legend, in relation to the size of the plot axes.
legend_bounds (tuple[float], optional) – The bounds of the legend, as
(x, y, width, height)
in axes space. If not provided, the bounds will be computed fromlegend_loc
andlegend_size
.legend_resolution (int, optional) – The number of different colors to show in the legend.
facecolor (str, optional) – The background color of the plot, by default transparent.
rasterize (int or float, optional) – Whether to rasterize the plot. If a number, then rasterize if the number of pixels in the plot is greater than this value.
rasterize_dpi (float, optional) – The dpi to use when rasterizing.
figsize (tuple[float], optional) – The size of the figure to create, if
ax
is not provided.ax (matplotlib.Axis, optional) – The axis to draw to. If not provided, a new figure will be created.
show_and_close (bool, optional) – If
True
(the default) then show and close the figure, otherwise return the figure and axis.
- Returns:
fig (matplotlib.Figure) – The figure containing the plot, or
None
ifax
was provided.ax (matplotlib.Axis) – The axis or axes containing the plot(s).
- xyzpy.plot.plotter_matplotlib.visualize_tensor(array, spacing_factor=1.0, max_projections=None, projection_overlap_spacing=1.05, angles=None, scales=None, skew_angle_factor='auto', skew_scale_factor=0.05, max_mag=None, magscale='linear', size_map=True, size_pow=1 / 2, size_scale=1.0, alpha_map=True, alpha_pow=1 / 2, alpha=0.8, marker='o', linewidths=0, show_lattice=True, lattice_opts=None, compass=False, compass_loc='auto', compass_size=0.1, compass_bounds=None, compass_labels=None, compass_opts=None, legend=True, legend_loc='auto', legend_size=0.15, legend_bounds=None, legend_resolution=3, interleave_projections=False, reverse_projections=False, facecolor=None, rasterize=4096, rasterize_dpi=300, figsize=(5, 5), ax=None)[source]#
Visualize all entries of a tensor, with indices mapped into the plane and values mapped into a color wheel.
- Parameters:
array (numpy.ndarray) – The tensor to visualize.
spacing_factor (float, optional) – How to scale the dimensions relative to each other. If 1.0, then each dimension will have the same extent, and smaller dimensions will be sparser. If 0.0, the each dimension will have an extent propoertional to its size, with matching density.
max_projections (int, optional) – The maximum number of different projection directions / angles to use. If specified and less than the number of dimensions, then multiple dimensions will share the same angle but with different scales.
projection_overlap_spacing (float, optional) – When grouping multiple dimensions to the same angle, how much to increase the spacing at each scale so as to emphasize each.
angles (sequence[float], optional) – An explicit list of angles to use for each direction, in radians, with zero pointing straight down. If not provided, then the angles will be calculated automatically.
scales (sequence[float], optional) – An explicit list of scales to use for each direction. If not provided, then the scales will be calculated automatically.
skew_angle_factor (float, optional) – When there are more than two dimensions, a factor to scale the rotations by to avoid overlapping data points. If 0.0 then the angles will be evenly spaced.
skew_scale_factor (float, optional) – When there are more than two dimensions, a factor to scale the scales by to avoid overlapping data points, that shortens non-perpendicular directions.
max_mag (float, optional) – The maximum magnitude to use for the color mapping. If not provided, the maximum magnitude in the array will be used.
magscale ("linear" or float, optional) – How to scale the magnitude of the array values. If “linear”, then the magnitude is used directly. If a float, then the magnitude is raised to this power before being used, which can help to show variation among small values.
size_map (bool, optional) – Whether to map the tensor value magnitudes to marker size.
size_scale (float, optional) – An overall factor to scale the marker size by.
alpha_map (bool, optional) – Whether to map the tensor value magnitudes to marker alpha.
alpha_pow (float, optional) – The power to raise the magnitude to when mapping to alpha.
alpha (float, optional) – The overall alpha to use for all markers if
not alpha_map
.marker (str, optional) – The marker to use for the markers.
linewidths (float, optional) – The linewidth to use for the markers.
show_lattice (bool, optional) – Show a thin grey line connecting adjacent array coordinate points.
lattice_opts (dict, optional) – Options to pass to
maplotlib.Axis.scatter
for the lattice grid.compass (bool, optional) – Whether to show a compass indicating the orientation of each dimension.
compass_loc ((float, float), optional) – Where to place the compass.
compass_size (float, optional) – The size of the compass.
compass_bounds (tuple[float], optional) – Explicit bounds of the compass, as
(x, y, width, height)
.compass_labels (sequence[str], optional) – Explicit labels for the compass, in order of the dimensions.
compass_opts (dict, optional) – Extra options for the compass arrows.
legend (bool, optional) – Whether to show a legend (colorbar). If the array has complex dtype then the legend will be a colorwheel.
legend_loc (str or tuple[float], optional) – Where to place the legend. If “auto”, then the legend will be placed outside the plot rectangle, otherwise it should be a tuple of
(x, y)
coordinates in axes space.legend_size (float, optional) – The size of the legend, in relation to the size of the plot axes.
legend_bounds (tuple[float], optional) – Explicit bounds of the legend, as
(x, y, width, height)
in axes space.legend_resolution (int, optional) – The number of different colors to show in the legend.
interleave_projections (bool, optional) – If
True
and grouping dimensions, then they are assigned round robin fashion rather than blocks.False
matches the behavior of fusing.reverse_projections (bool, optional) – Whether to reverse the order of the projections.
facecolor (str, optional) – The background color of the plot, by default transparent.
rasterize (int or float, optional) – Whether to rasterize the plot. If a number, then rasterize if the size of the array is greater than this value.
rasterize_dpi (float, optional) – The dpi to use when rasterizing.
figsize (tuple, optional) – The size of the figure to create, if
ax
is not provided.ax (matplotlib.Axis, optional) – The axis to draw to. If not provided, a new figure will be created.
- Returns:
fig (matplotlib.Figure) – The figure containing the plot, or
None
ifax
was provided.ax (matplotlib.Axis) – The axis containing the plot.