Skip to content

Stem

daspi.plotlib.plotter.Stem(source, target, feature='', bottom=0, target_on_y=True, color=None, line_color=None, base_color=None, marker=None, ax=None, visible_spines=None, hide_axis=None, **kwds)

Bases: Plotter

A stem plotter that extends the Plotter base class.

This class is designed to create a stem plot using the data provided in the source DataFrame.

PARAMETER DESCRIPTION
source

A long format DataFrame containing the data source for the plot.

TYPE: pandas DataFrame

target

Column name of the target variable for the plot.

TYPE: str

feature

Column name of the feature variable for the plot.

TYPE: str DEFAULT: ''

bottom

The Y/X position of the baseline (depending on the orientation or target_on_y). Default is 0.

TYPE: float DEFAULT: 0

target_on_y

Flag indicating whether the target variable is plotted on the y-axis, by default True.

TYPE: bool DEFAULT: True

color

Color to be used to draw the markers. If None, the first color is taken from the color cycle, by default None.

TYPE: str | None DEFAULT: None

line_color

Color to be used to draw the vertical lines. If None, the same color is taken as the color of the markers. Default is None

TYPE: str | None DEFAULT: None

base_color

Color to be used to draw the base line. If None, the same color is taken as the color of the markers. Default is None

TYPE: str | None DEFAULT: None

marker

The marker style for the stem plot. Available markers see: https://matplotlib.org/stable/api/markers_api.html, by default None.

TYPE: str | None DEFAULT: None

ax

The axes object for the plot. If None, the current axes is fetched using plt.gca(). If no axes are available, a new one is created. Defaults to None.

TYPE: Axes | None DEFAULT: None

visible_spines

Specifies which spines are visible, the others are hidden. If 'none', no spines are visible. If None, the spines are drawn according to the stylesheet. Defaults to None.

TYPE: Literal['target', 'feature', 'none'] | None DEFAULT: None

hide_axis

Specifies which axes should be hidden. If None, no changes are made, and the axes are displayed according to the stylesheet. Defaults to None.

TYPE: Literal['target', 'feature', 'both'] | None DEFAULT: None

**kwds

Additional keyword arguments that may be used for compatibility with other chart objects.

DEFAULT: {}

Examples:

Apply to an existing Axes object:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from daspi import Stem

fig, ax = plt.subplots()
df = pd.DataFrame({'x': list(x*np.pi/25 for x in range(50))})
df['y'] = np.cos(df['x'])
stem = Stem(
    source=df, target='y', feature='x', target_on_y=False, bottom=1,
    color='deepskyblue', line_color='steelblue', base_color='skyblue',
    ax=ax)
stem(alpha=0.2, line_style='--', base_line_style='-.')

Apply using the plot method of a DaSPi Chart object:

import numpy as np
import daspi as dsp
import pandas as pd

df = pd.DataFrame({'x': list(x*np.pi/25 for x in range(50))})
df['y'] = np.cos(df['x'])

chart = dsp.SingleChart(
        source=df,
        target='y',
        feature='x',
        target_on_y=False
    ).plot(
        dsp.Stem,
        bottom=1,
        color='deepskyblue',
        line_color='steelblue',
        base_color='skyblue',
        kw_call=dict(alpha=0.2, line_style='--', base_line_style='-.'))
Notes

To change the markers, vertical lines and base line when drawing use the keword arguments markerfmt, linefmt and basefmt. For further information see: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.stem.html

bottom = bottom instance-attribute

The Y/X position of the baseline (depending on the orientation or target_on_y).

line_color = line_color if line_color is not None else self.color instance-attribute

Color to be used to draw the vertical lines. If None, the same color is taken as the color of the markers.

base_color = base_color if base_color is not None else self.color instance-attribute

Color to be used to draw the base line. If None, the same color is taken as the color of the markers.

kw_default property

Default keyword arguments for plotting (read-only)