xyzpy.plot.plotter_matplotlib#

Functions for plotting datasets nicely.

Functions

add_visualize_legend(ax, complexobj, ...[, ...])

auto_heatmap(x, **heatmap_opts)

Auto version of heatmap() that accepts array arguments by converting them to a Dataset first.

auto_histogram(x, **histogram_opts)

Auto version of histogram() that accepts array arguments by converting them to a Dataset first.

auto_lineplot(x, y_z, **lineplot_opts)

Auto version of lineplot() that accepts array arguments by converting them to a Dataset first.

auto_scatter(x, y_z, **scatter_opts)

Auto version of scatter() that accepts array arguments by converting them to a Dataset first.

choose_squarest_grid(x)

handle_sequence_of_arrays(vis_fn)

Simple wrapper to handle sequence of arrays as input to e.g.

heatmap(ds, x, y, z, **kwargs)

From ds plot variable z as a function of x and y using a 2D heatmap.

histogram(ds, x[, z])

Dataset histogram.

lineplot(ds, x, y[, z, y_err, x_err])

From ds plot lines of y as a function of x, optionally for varying z.

mpl_multi_plot(fn)

Decorate a plotting function to plot a grid of values.

scatter(ds, x, y[, z, y_err, x_err])

From ds plot a scatter of y against x, optionally for varying z.

setup_fig_ax([facecolor, rasterize, ...])

to_colors(zs[, magscale, max_mag, ...])

visualize_matrix(array[, max_mag, legend, ...])

visualize_tensor(array[, max_projections, ...])

Visualize all entries of a tensor, with indices mapped into the plane and values mapped into a color wheel.

Classes

AutoHeatMap(x, **heatmap_opts)

AutoHistogram(x, **histogram_opts)

AutoLinePlot(x, y_z, **lineplot_opts)

AutoScatter(x, y_z, **scatter_opts)

HeatMap(ds, x, y, z, **kwargs)

Histogram(ds, x[, z])

LinePlot(ds, x, y[, z, y_err, x_err])

PlotterMatplotlib(ds, x, y[, z, y_err, x_err])

Scatter(ds, x, y[, z])

class xyzpy.plot.plotter_matplotlib.LinePlot(ds, x, y, z=None, *, y_err=None, x_err=None, **kwargs)[source]#
plot_lines()[source]#
class xyzpy.plot.plotter_matplotlib.PlotterMatplotlib(ds, x, y, z=None, y_err=None, x_err=None, **kwargs)[source]#
plot_colorbar(grid=False)[source]#

Add a colorbar to the data.

plot_legend(grid=False, labels_handles=None)[source]#

Add a legend

prepare_axes()[source]#
prepare_plot()[source]#

Do all the things that every plot has.

set_axes_range()[source]#
set_axes_scale()[source]#
set_gridlines()[source]#
set_mappable()[source]#

Mappale object for colorbars.

set_spans()[source]#
set_tick_marks()[source]#
xyzpy.plot.plotter_matplotlib.auto_heatmap(x, **heatmap_opts)[source]#

Auto version of heatmap() that accepts array arguments by converting them to a Dataset first.

xyzpy.plot.plotter_matplotlib.auto_histogram(x, **histogram_opts)[source]#

Auto version of histogram() that accepts array arguments by converting them to a Dataset first.

xyzpy.plot.plotter_matplotlib.auto_lineplot(x, y_z, **lineplot_opts)[source]#

Auto version of lineplot() that accepts array arguments by converting them to a Dataset first.

xyzpy.plot.plotter_matplotlib.auto_scatter(x, y_z, **scatter_opts)[source]#

Auto version of scatter() that accepts array arguments by converting them to a Dataset first.

xyzpy.plot.plotter_matplotlib.handle_sequence_of_arrays(vis_fn)[source]#

Simple wrapper to handle sequence of arrays as input to e.g. visualize_tensor.

xyzpy.plot.plotter_matplotlib.heatmap(ds, x, y, z, **kwargs)[source]#

From ds plot variable z as a function of x and y 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.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.lineplot(ds, x, y, z=None, y_err=None, x_err=None, **plot_opts)[source]#

From ds plot lines of y as a function of x, optionally for varying z.

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.mpl_multi_plot(fn)[source]#

Decorate a plotting function to plot a grid of values.

xyzpy.plot.plotter_matplotlib.scatter(ds, x, y, z=None, y_err=None, x_err=None, **plot_opts)[source]#

From ds plot a scatter of y against x, optionally for varying z.

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.visualize_tensor(array, max_projections=None, angles=None, scales=None, projection_overlap_spacing=1.05, skew_factor=0.05, spacing_factor=1.0, magscale='linear', size_map=True, size_pow=0.5, size_scale=1.0, alpha_map=True, alpha_pow=0.5, 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, max_mag=None, legend=False, 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 (ndarray) – The tensor to visualize.

  • skew_factor (float, optional) – When there are more than two dimensions, a factor to scale the rotations by to avoid overlapping data points.

  • 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.

  • show_lattice (bool, optional) – Show a small grey dot for every ‘lattice’ point regardless of value.

  • lattice_opts (dict, optional) – Options to pass to maplotlib.Axis.scatter for the lattice points.

  • linewidths (float, optional) – The linewidth to use for the markers.

  • marker (str, optional) – The marker to use for the markers.

  • 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 if ax was provided.

  • ax (matplotlib.Axis) – The axis containing the plot.