Skip to content
James Ramsden edited this page Mar 26, 2025 · 2 revisions

Python Toolkit implements several plots. These are implementations of matplotlib plots, and it is generally expected that these will be implemented by child python toolkits.

In the following documentation for these plots, the following datasets are used for the examples.

import pandas as pd
import random
import math

# create an example time-indexed series
date_range = pd.date_range(start='2017-01-01T00:00', end='2017-12-31T23:59', freq='h')
data = [-math.cos(2 * math.pi * d.hour / 24) + random.random() for d in date_range]
TIME_INDEXED_SERIES = pd.Series(data, index=date_range)

Diurnal

Plot a profile aggregated across days in the specified timeframe.

Args:
    series (pd.Series):
        A time-indexed Pandas Series object.
    ax (plt.Axes, optional):
        A matplotlib Axes object. Defaults to None.
    period (str, optional):
        The period to aggregate over. Must be one of "daily", "weekly", or "monthly". Defaults to "daily".
    **kwargs (Dict[str, Any], optional):
        Additional keyword arguments to pass to the matplotlib plotting function.
        legend (bool, optional):
            If True, show the legend. Defaults to True.

Returns:
    plt.Axes:
        A matplotlib Axes object.

Example

Create a diurnal plot with default parameters (defaults to daily):

download

from python_toolkit.plot.diurnal import diurnal
diurnal(TIME_INDEXED_SERIES)

Create a weekly diurnal plot:

download

from python_toolkit.plot.diurnal import diurnal
diurnal(TIME_INDEXED_SERIES, period="weekly")

Create a monthly diurnal plot:

download

from python_toolkit.plot.diurnal import diurnal
diurnal(TIME_INDEXED_SERIES, period="monthly")

Heatmap

Create a heatmap of a pandas Series.

Args:
    series (pd.Series):
        The pandas Series to plot. Must have a datetime index.
    ax (plt.Axes, optional):
        An optional plt.Axes object to populate. Defaults to None, which creates a new plt.Axes object.
    **kwargs:
        Additional keyword arguments to pass to plt.pcolormesh().
        show_colorbar (bool, optional):
            If True, show the colorbar. Defaults to True.
        title (str, optional):
            The title of the plot. Defaults to None.
        mask (List[bool], optional):
            A list of booleans to mask the data. Defaults to None.

Returns:
    plt.Axes:
        The populated plt.Axes object.

Example

download

from python_toolkit.plot.heatmap import heatmap
heatmap(TIME_INDEXED_SERIES)
Clone this wiki locally