I compute dimensions of text strings and Matplotlib text objects, using my default DPI of 100 or a different one you supply in my constructor.

Method __init__ Undocumented
Method width Returns an estimated width of the supplied text proportional to full height of a full-height letter of the specified size. For Arial font.
Method height Returns an estimated height of the supplied text proportional to that of a full-height letter of the specified size, based on the number of lines it contains.
Method realistic_dims Returns the dimensions of the supplied textObj, initially computed from its bounding box but replaced by an estimate if they weren't realistic.
Method dims Returns the dimensions of the supplied text object in pixels.
Static Method pixels2fraction Given a 2-sequence of dimensions dimsObj of some object and another 2-sequence of dimensions dimsFig of the figure, returns fractional dimensions.
def __init__(self, DPI=None):
Undocumented
def width(self, text, size):

Returns an estimated width of the supplied text proportional to full height of a full-height letter of the specified size. For Arial font.

Adapted from https://stackoverflow.com/a/16008023.

def height(self, text, size):

Returns an estimated height of the supplied text proportional to that of a full-height letter of the specified size, based on the number of lines it contains.

def realistic_dims(self, textObj, size):

Returns the dimensions of the supplied textObj, initially computed from its bounding box but replaced by an estimate if they weren't realistic.

You must supply a size as a float. Call this method indirectly via dims.

@lru_cache(128)
def dims(self, textObj, size=None):

Returns the dimensions of the supplied text object in pixels.

If there's no renderer yet, estimates the dimensions based on font size and DPI.

If you supply a string as the textObj, you must also specify the font size.

@staticmethod
def pixels2fraction(dimsObj, dimsFig):

Given a 2-sequence of dimensions dimsObj of some object and another 2-sequence of dimensions dimsFig of the figure, returns fractional dimensions.

API Documentation for yampex, generated by pydoctor at 2022-11-21 15:03:54.