API reference#

Core#

Module containing the core functionality of the project.

class figure_scale.core.FigSize(width: float, height: float)#

Bases: NamedTuple

A named tuple to hold figure size information to be used with matplotlib.

height: float#

Alias for field number 1

scale(scalar: int | float | Fraction) FigSize#

Convenience method to scale the figure size by a scalar value.

Parameters:

scalar – The scalar value to scale the figure size by.

Returns:

A new FigSize instance with the scaled width and height.

Raises:

TypeError – If the scalar is not an integer, float, or Fraction.

width: float#

Alias for field number 0

class figure_scale.core.FigureScale(units: str = 'in', width: float | int | None = None, height: float | int | None = None, aspect: float | int | None = None)#

Bases: Sequence

Class to hold figure scale information.

This class implements the Sequence interface, allowing it to be used as a tuple-like object. It can be used to seamlessly set the figure.figsize parameter in matplotlib.

The initialization accepts its units, besides two of the following three parameters:

  • width: The width of the figure in the specified units.

  • height: The height of the figure in the specified units.

  • aspect: The aspect ratio of the figure (width / height).

The missing parameter will be computed based on the provided ones.

It is set as a frozen dataclass to ensure constancy and immutability of the figure scale after creation. See the FigureScale.replace method for a way to create a new instance with modified attributes.

Examples

See the User Guide for examples of how to use this class.

__call__(**kwargs) Iterator[None]#

A context manager to set the figure size in matplotlib locally on your code.

This also enable it to be used as a decorator.

__eq__(other: object) bool#

Compare the figure scale with another object by delegating to the internal FigSize.

__getitem__(index: slice | int)#

Get items for sequence-like access by delegating to the internal FigSize.

__len__() int#

Get the length for sequence-like access by delegating to the internal FigSize.

__post_init__()#

Compute additional internal values.

replace(**kwargs) FigureScale#

Replace the attributes of the figure scale.

set_as_default()#

Set the figure scale as the default on matplotlib.

Unit Conversion#

Hold the table of conversion factors from other units to inches.

figure_scale.unit_conversion.UnitConversionMapping()#

A singleton dictionary class to hold the conversion factors from other units to inches.

Examples

See the User Guide for examples of how to use this class.