Detailed API documentation#

class swanplot.axes#

A class to represent axes for plotting data, including color schemes, data options, and methods for plotting and saving figures.

Methods:

hist(datacube)

Create a histogram from the provided 3D image data.

figsize(width, height[, margin])

Set the figure's dimensions and margin.

set_unit(unit, axis)

Set the unit for the specified axis.

uniform_ticks(start, end, axis)

Generate and set uniform ticks for the specified axis.

custom_ticks(input, axis)

Set custom ticks for the specified axis.

set_label(string, axis)

Assign labels to the specified axis.

set_loop([loop])

Configure whether the plot should loop.

cmap(colors, positions)

Set the color map for the axes.

savefig(fname[, style, format, force, ...])

Save the figure to a specified file.

hist(datacube)#

Create a histogram from the provided 3D image data.

This method generates a TIFF image from the data and updates the figure options with intensity and axis information.

Parameters:

datacube (ndarray) – A 3D NumPy array representing the image data, where the first dimension corresponds to timesteps.

figsize(width, height, margin=None)#

Set the figure’s dimensions and margin.

If no margin is provided, and width and height are already set, the provided width and height are assumed to be the total width and total height of the figure.

Parameters:
  • width (int) – Width of the figure in pixels.

  • height (int) – Height of the figure in pixels.

  • margin (int | None) – Margin around the figure in pixels (optional).

set_unit(unit, axis)#

Set the unit for the specified axis.

This method updates the unit of measurement for the specified axis (time, x, y, or c) in the figure options.

Parameters:
  • unit (str) – The unit to set for the specified axis.

  • axis (DataAxes) – The axis for which to set the unit. Can be “t”, “x”, “y”, “c” or their corresponding integer values (0, 1, 2, 3).

uniform_ticks(start, end, axis)#

Generate and set uniform ticks for the specified axis.

This method creates evenly spaced ticks between the specified start and end values for the given axis.

Parameters:
  • start (float) – The start value for the axis.

  • end (float) – The end value for the axis.

  • axis (DataAxes) – The axis for which to set the ticks. Can be “t”, “x”, “y”, “c” or their corresponding integer values (0, 1, 2, 3).

Raises:

Exception – If the number of timesteps is not defined. Set uniform ticks for the specified axis.

custom_ticks(input, axis)#

Set custom ticks for the specified axis.

This method allows the user to define specific tick values for the given axis, ensuring the number of ticks matches the number of timesteps in the data.

Parameters:
  • input (Sequence[float]) – A sequence of float values representing the custom ticks.

  • axis (DataAxes) – The axis for which to set the custom ticks. Can be “t”, “x”,”y”,”c” or their corresponding integer values (0, 1, 2, 3).

Raises:

Exception – If the number of timesteps is not defined or if the length of provided ticks does not match the number of timesteps.

set_label(string, axis)#

Assign labels to the specified axis.

This method updates the label for the specified axis (time, x, y, or c) in the figure options. It can handle both single strings and sequences of strings.

Parameters:
  • string (StringInput) – The label(s) to set for the specified axis.

  • axis (AxesInput) – The axis for which to set the label. Can be “t”, “x”, “y”, “c” or their corresponding integer values (0, 1, 2, 3).

Raises:

Exception – If the provided string and axis types do not match or if their lengths are inconsistent.

set_loop(loop=True)#

Configure whether the plot should loop.

This method sets the looping behavior of the plot, allowing it to repeat indefinitely if desired.

Parameters:

loop (bool) – If True, the plot will loop; otherwise, it will not.

cmap(colors, positions)#

Set the color map for the axes.

This method defines the color scheme for the plot by specifying the colors and their corresponding positions in the color map.

Parameters:
  • colors (ColorStrings) – A sequence of colors to use in the color scheme. Can include color names or CSS color values.

  • positions (IntensityValues) – A sequence of float values representing the positions corresponding to the colors, ranging from 0 to 1.

savefig(fname, style='compact', format=None, force=False, print_website=True)#

Save the figure to a specified file.

This method allows the user to save the figure in either JSON or TIFF format, with options for output style and file extension verification.

Parameters:
  • fname (str) – The filename to save the figure to.

  • style ('pretty' | 'compact') – The style of the output (pretty or compact).

  • format ('json' | 'tiff' | None) – The format to save the figure in (currently supports json and tiff) defaults to json if no extension is filename is bare.

  • force (bool) – If True, allows saving with a different file extension than the specified format.

  • print_website (bool) – If True, prints a message with the upload link after saving.

Raises:

Exception – If the specified format does not match the file extension and force is False.