Skip to content

viz/base.py

VizBase

VizBase(dpi: int = 150, font_size: int = 11, font_family: str = 'Arial')

Provide a visualization class.

Parameters:

  • dpi

    (int, default: 150 ) –

    set resolution for rasterized images

  • font_size

    (int, default: 11 ) –

    set MatPlotLib default font size

  • font_family

    (str, default: 'Arial' ) –

    set MatPlotLib default font family

Attributes:

  • dpi (int) –

    rasterization resolution

  • fdict (dict) –

    dictionary to which each figure is appended as it is generated

  • markers (dict) –

    selected markers for scatter plots

Methods:

Source code in wmbe/viz/base.py
def __init__(
        self, 
        dpi: int=150, 
        font_size: int=11, 
        font_family: str="Arial",
    ) -> None:
    self.dpi = dpi
    self.fdict = {}
    try:
        mpl.rc("font", size=font_size, family=font_family)
    except:
        mpl.rc("font", size=font_size, family="")

    self.markers = {
        'o': 'circle', 
        'v': 'triangle_down', 
        '^': 'triangle_up', 
        '<': 'triangle_left', 
        '>': 'triangle_right', 
        #  '1': 'tri_down', '2': 'tri_up', 
        #  '3': 'tri_left', '4': 'tri_right',
        #  's': 'square', 
        '8': 'octagon', 
        'p': 'pentagon', 
        # '*': 'star', 
        'h': 'hexagon1',
        'H': 'hexagon2', 
        #  '+': 'plus', 'x': 'x', 
        'D': 'diamond', 
        'd': 'thin_diamond', 
        '|': 'vline', 
        '_': 'hline', 
        'P': 'plus_filled', 
        'X': 'x_filled', 
        #  0: 'tickleft', 1: 'tickright', 
        #  2: 'tickup', 3: 'tickdown', 
        #  4: 'caretleft', 5: 'caretright', 6: 'caretup',
        #  7: 'caretdown', 8: 'caretleftbase', 
        #  9: 'caretrightbase', 10: 'caretupbase', 11: 'caretdownbase'
    }

create_figure

create_figure(
    name: str, size: tuple[float, float] | None = None, dpi: int | None = None
) -> Figure

Initialize a Pyplot figure.

Set its size and DPI. Append it to the figures dictionary.

Parameters:

  • name

    (str) –

    name of figure; used as key in figures dictionary

  • size

    (tuple[float, float] | None, default: None ) –

    optional width and height of figure in inches

  • dpi

    (int | None, default: None ) –

    rasterization resolution

Returns:

  • Figure

    reference to MatPlotLib/Pyplot figure

Source code in wmbe/viz/base.py
def create_figure(
    self,
    name: str,
    size: tuple[float, float] | None = None,
    dpi: int | None = None,
) -> Figure:
    """
    Initialize a Pyplot figure.

    Set its size and DPI. Append it to the figures dictionary.

    Args:
        name:
            name of figure; used as key in figures dictionary
        size:
            optional width and height of figure in inches
        dpi:
            rasterization resolution

    Returns:
        reference to MatPlotLib/Pyplot figure
    """
    fig_size_: tuple[float, float] = (
        (6, 4,) if size is None else size
    )
    dpi_: float = self.dpi if dpi is None else dpi
    logging.info(
        "Viz:\n   "
        + f"Creating plot: {name} size={fig_size_} @ {dpi_} dpi"
    )
    fig = plt.figure()
    self.fdict.update({name: fig})
    if fig_size_ is not None:
        fig.set_size_inches(*fig_size_)
    fig.set_dpi(dpi_)
    return fig