Skip to content

grid

Grid (major/minor gridline styling for a plot axes) and its GridTheme presets, selectable via Grid.from_theme, plus the per-axis GridAxis settings a Grid is built from.

GridAxis

Bases: HashableBase

Controls styling and visibility for one type of grid (major or minor).

show class-attribute instance-attribute

Python
show: bool = False

Whether to display this grid axis.

pen class-attribute instance-attribute

Python
pen: Pen = Pen(
    color="gray",
    alpha=1.0,
    size=0.75,
    linestyle="-",
    label=None,
)

Style and label information for drawing to matplotlib axes.

__hash__

Python
__hash__()

Defines hash function

Source code in src/trendify/base/helpers.py
Python
def __hash__(self):
    """
    Defines hash function
    """
    return hash((type(self), *tuple(self.__dict__.values())))

Grid

Bases: HashableBase

Container for major and minor grid line configuration.

major class-attribute instance-attribute

Python
major: GridAxis = GridAxis(show=False)

Configuration for major grid lines.

minor class-attribute instance-attribute

Python
minor: GridAxis = GridAxis(show=False)

Configuration for minor grid lines.

enable_minor_ticks class-attribute instance-attribute

Python
enable_minor_ticks: bool = False

Whether to enable minor ticks on the axes.

zorder class-attribute instance-attribute

Python
zorder: float = -1

Prioritization of the grid lines relative to plotted data.

from_theme classmethod

Python
from_theme(name: GridTheme) -> Grid

Predefined themes for common grid styles.

Source code in src/trendify/styling/grid.py
Python
@classmethod
def from_theme(cls, name: GridTheme) -> Grid:
    """
    Predefined themes for common grid styles.
    """
    themes = {
        GridTheme.MATLAB: cls(
            major=GridAxis(
                show=True,
                pen=Pen(
                    color="#b0b0b0",
                    linestyle="-",
                    size=0.8,
                    alpha=0.35,
                    label=None,
                ),
            ),
            minor=GridAxis(
                show=True,
                pen=Pen(
                    color="#b0b0b0",
                    linestyle=(0, (3, 1, 1, 1)),
                    size=0.6,
                    alpha=0.25,
                    label=None,
                ),
            ),
            enable_minor_ticks=True,
        ),
        GridTheme.LIGHT: cls(
            major=GridAxis(
                show=True,
                pen=Pen(
                    color="#E0E0E0",
                    linestyle="--",
                    size=0.7,
                    alpha=0.9,
                    label=None,
                ),
            ),
            minor=GridAxis(show=False),
            enable_minor_ticks=False,
        ),
        GridTheme.DARK: cls(
            major=GridAxis(
                show=True,
                pen=Pen(
                    color="#444444",
                    linestyle="--",
                    size=0.7,
                    alpha=0.5,
                    label=None,
                ),
            ),
            minor=GridAxis(show=False),
            enable_minor_ticks=False,
        ),
    }

    try:
        return themes[name]
    except KeyError:
        raise ValueError(f"Unknown grid theme: {name!r}")

__hash__

Python
__hash__()

Defines hash function

Source code in src/trendify/base/helpers.py
Python
def __hash__(self):
    """
    Defines hash function
    """
    return hash((type(self), *tuple(self.__dict__.values())))