plans.viewer#

Handle plots in matplotlib

Call constants and functions from this module in order to built plots with matplotlib.

Functions

build_fig(specs)

Builds a matplotlib figure and GridSpec object based on the given specifications.

clear_xticks(axes)

Lower the y axis when a y grid line would cross the inward x ticks.

get_annotation_specs()

Get the style of annotations, such as statistics and values inside a panel.

get_discrete_cmap(n_classes[, base_cmap_name])

Creates a colormap suitable for plotting classification.

set_colors([style])

Sets the color scheme for the plot, including figure background, axes background, grid, lines, and text.

set_figsize(width_mm, height_mm)

Sets the figure size in millimeters.

set_fonts([style])

Sets the font styles and sizes for plots.

set_frame([style])

Sets the frame style, including ticks, tick labels, axes, and grid.

set_layers(fig)

Set the drawing order of all panels of a figure.

set_style([style])

Sets the viwer style.

ship_fig(fig[, show, file_output, dpi])

Handles the output of a matplotlib figure, either by showing it or saving it to a file.

Classes

AxisGrid(*args, **kwargs)

Grid lines of one axis, as an artist with its own drawing order.

CoordinateLocator(*args, **kwargs)

Locator of a fixed number of round ticks inside the view, for map coordinates.

plans.viewer.set_figsize(width_mm, height_mm)[source]#

Sets the figure size in millimeters.

Parameters:
  • width_mm (float) – The width of the figure in millimeters.

  • height_mm (float) – The height of the figure in millimeters.

plans.viewer.set_style(style=None)[source]#

Sets the viwer style. options: bare, dark, seaborn, wien, wien-light, wien-clean

Parameters:

style (str) – [optional] The style of the fonts. Default value = “bare”

plans.viewer.set_fonts(style=None)[source]#

Sets the font styles and sizes for plots.

Parameters:

style (str) – [optional] The style of the fonts. Default value = “bare”

plans.viewer.set_frame(style=None)[source]#

Sets the frame style, including ticks, tick labels, axes, and grid.

Parameters:

style (str) – [optional] The style of the frame. Default value = “bare”

plans.viewer.set_colors(style=None)[source]#

Sets the color scheme for the plot, including figure background, axes background, grid, lines, and text.

Parameters:

style (str) – [optional] The color style to apply. Default value = “bare”

plans.viewer.build_fig(specs)[source]#

Builds a matplotlib figure and GridSpec object based on the given specifications.

Parameters:

specs (dict) – A dictionary containing the specifications for the figure and GridSpec. It should include ‘width’, ‘height’, ‘nrows’, ‘ncols’, ‘gs_wspace’, ‘gs_hspace’, ‘gs_left’, ‘gs_right’, ‘gs_bottom’, ‘gs_top’, and optionally ‘style’.

Returns:

A tuple containing the matplotlib figure and GridSpec object.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.gridspec.GridSpec]

plans.viewer.ship_fig(fig, show=True, file_output=None, dpi=300)[source]#

Handles the output of a matplotlib figure, either by showing it or saving it to a file.

Parameters:
  • fig (matplotlib.figure.Figure) – The matplotlib figure to be handled.

  • show (bool) – Whether to display the figure. Default value = True

  • file_output (str) – [optional] The file path to save the figure. If None, the figure is not saved.

  • dpi (int) – The dots per inch for saving the figure. Default value = 300

Returns:

None if show or file_output is true, or the figure object if return_fig is true.

Return type:

matplotlib.figure.Figure or None

plans.viewer.clear_xticks(axes)[source]#

Lower the y axis when a y grid line would cross the inward x ticks.

Matplotlib draws each axis grid and ticks together, the y axis last, so a y grid line close to the bottom always covers the x ticks. A grid line right at the bottom is hidden by the frame, so it stays.

Parameters:

axes (list) – axes with the same y limits and height

Returns:

None

Return type:

None

plans.viewer.get_annotation_specs()[source]#

Get the style of annotations, such as statistics and values inside a panel.

Returns:

arguments of a text

Return type:

dict

class plans.viewer.CoordinateLocator(*args: Any, **kwargs: Any)[source]#

Bases: Locator

Locator of a fixed number of round ticks inside the view, for map coordinates.

__init__(n_ticks=3)[source]#
__call__()[source]#

Call self as a function.

tick_values(vmin, vmax)[source]#

Get the ticks of a view.

Parameters:
  • vmin (float) – lower limit of the view

  • vmax (float) – upper limit of the view

Returns:

ticks

Return type:

numpy.ndarray

__orig_bases__ = (matplotlib.ticker.Locator,)#
class plans.viewer.AxisGrid(*args: Any, **kwargs: Any)[source]#

Bases: Artist

Grid lines of one axis, as an artist with its own drawing order. An axis draws its ticks and its grid together, so they can not be on different layers.

__init__(axis, gridline)[source]#

Initialize the grid.

Parameters:
  • axis (matplotlib.axis.Axis) – axis to follow, for the positions of the lines

  • gridline (matplotlib.lines.Line2D) – line to copy the style from

draw(renderer)[source]#

Draw the lines at the current ticks of the axis.

Parameters:

renderer (matplotlib.backend_bases.RendererBase) – renderer of the figure

Returns:

None

Return type:

None

__orig_bases__ = (matplotlib.artist.Artist,)#
plans.viewer.set_layers(fig)[source]#

Set the drawing order of all panels of a figure. From the bottom to the top: background, raster, grid, plot elements (with their own order), ticks and frame.

Parameters:

fig (matplotlib.figure.Figure) – figure with all panels already plotted

Returns:

None

Return type:

None

plans.viewer.get_discrete_cmap(n_classes, base_cmap_name='viridis')[source]#

Creates a colormap suitable for plotting classification.

Parameters:
  • n_classes (int) – The number of classes.

  • base_cmap_name (str, optional) – The name of the base Matplotlib colormap. Defaults to ‘viridis’.

Returns:

A custom colormap.

Return type:

matplotlib.colors.ListedColormap