parampl package

Module contents

class parampl.ParaMPL(axes: Axes, transform: str = 'data', width: float = 1.0, spacing: float = 1.3, fontname: str | None = None, fontsize: float = None, family: str | None = None, weight: str | None = None, style: str | None = None, color: None | str | tuple[float, float, float] = None, rotation: float = 0.0, justify: str = 'left', zorder: float | None = 3)

Bases: object

ParaMPL object is able to write justified text for a particular axes. Default values can be fixed at initialization, but each time the write() method is used the text properties can be changed individually.

Parameters:
  • axes – matplotlib.axes.Axes in which to put the paragraphs

  • transform – the transform in which the coordinates are given. Currently supported: ‘data’

  • width – default width

  • spacing – default spacing

  • fontname – default font name

  • fontsize – default fontsize, uses matplotlib’s value at initialization if not specified

  • family – default font family, uses matplotlib’s value at initialization if not specified

  • weight – default font weight, uses matplotlib’s value at initialization if not specified

  • style – default style, uses matplotlib’s value at initialization if not specified

  • color – default text color

  • rotation – default text rotation

  • justify – default text justification

  • zorder – default zorder

avoid_rectangle(left: float, bottom: float, width: float, height: float)

add rectangles to avoid based on its dimensions

Parameters:
  • left – horizontal left limit

  • bottom – vertical bottom limit

  • width – rectangle’s width

  • height – rectangle’s height

Return type:

self

avoid_rectangle_limits(left: float, right: float, bottom: float, top: float)

Add rectangles to avoid whenever ha=’left’, va=’top’, rotation=0 on write()

Parameters:
  • left (float) – left x-limit of the rectangle

  • right (float) – right x-limit of the rectangle

  • bottom (float) – bottom y-limit of the rectangle

  • top (float) – top y-limit of the rectangle

get_axes()

Return matplotlib axes being used

reset_rectangles()

Reset avoidance rectangles

write(text: str, xy: tuple[float, float], width: float | None = None, spacing: float | None = None, max_height: float | None = None, fontname: str | None = None, fontsize: float | None = None, family: str | None = None, weight: str | None = None, style: str | None = None, color: str | None = None, rotation: float | None = None, justify: str | None = None, zorder: float | None = None, ha: str = 'left', va: str = 'top', avoid_left_of: tuple[float, tuple[float, float]] | list[tuple[float, tuple[float, float]]] = None, avoid_right_of: tuple[float, tuple[float, float]] | list[tuple[float, tuple[float, float]]] = None, avoid_rectangles: bool = True, collapse_whites: bool = True, paragraph_per_line: bool = False) tuple[list[Artist], float]

Write text into a paragraph, storing word length in dictionary cache. Return a list to all artists

Parameters:
text:

text to write

xy:

position to place the paragraph aligned according to ha and va

width:

width of paragraph

spacing

line spacing of paragraph

max_height:

maximum height of paragraph, remaining characters are stored in .leftover attribute

fontname:

specific fontname, if not specified then use family

fontsize:

use this fontsize instead of the initialized one

family:

family of the font

weight:

font weight

style:

font style

color:

color of text

rotation:

anticlockwise rotation

justify:

Line’s justification

zorder:

Text’s zorder

ha:

Paragraph horizontal alignment

va:

Paragraph vertical alignment

avoid_left_of: avoid_specification

tuple (x_lim, (y1, y2)). Avoid space left of x_lim between y1 and y2

avoid_right_of: avoid_specification

tuple (x_lim, (y1, y2)). Avoid space right of x_lim between y1 and y2

avoid_rectangles

whether to avoid specified rectangles (in any case, it only works if va=top, ha=left, rotation=0)

collapse_whites

whether multiple side-by-side withes should be considered as one

paragraph_per_line

if true, each new line is considered a new paragraph

Returns:
list[Artist]