Locations
locations
Convert between cm, inch, and fraction locations in matplotlib figures.
LocationMethod
module-attribute
LocationMethod = Literal['bounds', 'extent']
How to read a 4-tuple location.
"bounds": (x, y, width, height)"extent": (x0, y0, x1, y1), the corners
CMTransform
CMTransform(fig: Figure)
Bases: Transform
Convert coordinates from centimeters to figure fractions.
Works on a Matplotlib figure, with the origin at the upper left.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
The figure to calculate the transform on. |
required |
transform
Transform cm coordinates (upper left origin) to figure fractions.
InvertedCMTransform
Bases: Transform
Convert figure fractions to centimeters (upper left origin).
transform
Transform figure fractions to cm coordinates (upper left origin).
locationcm_to_position
locationcm_to_position(
fig: Figure,
location_corners: tuple[
centimetres, centimetres, centimetres, centimetres
],
) -> tuple[float, float, float, float]
Convert an upper left origin cm extent to a figure fraction rect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Figure to find the true size from. |
required |
location_corners
|
tuple of float
|
(x0, y0, x1, y1) corners in cm, origin at the upper left of the figure with y increasing downwards. |
required |
Returns:
| Type | Description |
|---|---|
tuple of float
|
(left, bottom, width, height) in figure fraction, origin at the lower left of
the figure with y increasing upwards. This is the form matplotlib's
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
cm_to_inch
Convert centimeters to inches.
inch_to_cm
Convert inches to centimeters.
cm_to_fraction
Convert a position in cm from the upper left to figure fraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Figure to find the size from. |
required |
xy
|
tuple of float
|
(x, y) in cm, origin at the upper left of the figure. |
required |
Returns:
| Type | Description |
|---|---|
tuple of float
|
(x, y) in figure fraction, origin at the lower left of the figure. |
fraction_to_cm
fraction_to_cm(
fig: Figure, xy: tuple[float, float]
) -> tuple[centimetres, centimetres]
Convert a figure fraction position to cm from the upper left.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Figure to find the size from. |
required |
xy
|
tuple of float
|
(x, y) in figure fraction, origin at the lower left of the figure. |
required |
Returns:
| Type | Description |
|---|---|
tuple of float
|
(x, y) in cm, origin at the upper left of the figure. |