Skip to content

Errorbar

daspi.plotlib.plotter.Errorbar(source, target, lower, upper, feature='', show_center=True, bars_same_color=False, skip_na=None, target_on_y=True, color=None, marker=None, ax=None, visible_spines=None, hide_axis=None, **kwds)

Bases: TransformPlotter

Class for creating error bar plotters.

PARAMETER DESCRIPTION
source

Pandas 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

lower

Column name of the lower error values.

TYPE: str

upper

Column name of the upper error values.

TYPE: str

feature

Column name of the feature variable for the plot, by default ''.

TYPE: str DEFAULT: ''

show_center

Flag indicating whether to show the center points, by default True.

TYPE: bool DEFAULT: True

bars_same_color

Flag indicating whether to use same color for error bars as markers for center. If False, the error bars are black, by default False

TYPE: bool DEFAULT: False

skip_na

Flag indicating whether to skip missing values in the feature grouped data, by default None - None, no missing values are skipped - all', grouped data is skipped if all values are missing - any', grouped data is skipped if any value is missing

TYPE: Literal['none', 'all', 'any'] DEFAULT: None

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 artists. If None, the first color is taken from the color cycle, by default None.

TYPE: str | None DEFAULT: None

marker

The marker style for the center points. 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, both axes are displayed. Defaults to None.

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

**kwds

Additional keyword arguments that have no effect and are only used to catch further arguments that have no use here (occurs when this class is used within 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 Errorbar
from collections import defaultdict

fig, ax = plt.subplots()
data = defaultdict(list)
data['x'] = ['first', 'second', 'third']
for loc in [3, 4, 2]:
    temp = np.random.normal(loc=loc, scale=1, size=10)
    x_bar = np.mean(temp)
    sem = np.std(temp, ddof=1) / np.sqrt(len(temp))
    data['x_bar'].append(x_bar)
    data['lower'].append(x_bar - sem)
    data['upper'].append(x_bar + sem)

df = pd.DataFrame(data)
errorbar = Errorbar(
    source=df, target='x_bar', feature='x', lower='lower', upper='upper',
    show_center=True, ax=ax)
errorbar(kw_center=dict(color='black', s=30, marker='_')
errorbar.label_feature_ticks()

Apply using the plot method of a DaSPi Chart object:

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

from collections import defaultdict

data = defaultdict(list)
data['x'] = ['first', 'second', 'third']
for loc in [3, 4, 2]:
    temp = np.random.normal(loc=loc, scale=1, size=10)
    x_bar = np.mean(temp)
    sem = np.std(temp, ddof=1) / np.sqrt(len(temp))
    data['x_bar'].append(x_bar)
    data['lower'].append(x_bar - sem)
    data['upper'].append(x_bar + sem)

chart = dsp.SingleChart(
        source=df,
        target='x_bar',
        hue='x',
        dodge=True,
    ).plot(
        dsp.Errorbar,
        lower='lower',
        upper='upper',
        bars_same_color=True,
        kw_call={'kw_center': dict(color='black', s=30, marker='_')}
    ).label() # neded to add legend

lower = lower instance-attribute

Column name of the lower error values.

upper = upper instance-attribute

Column name of the upper error values.

show_center = show_center instance-attribute

Flag indicating whether to show the center points.

bars_same_color = bars_same_color instance-attribute

Flag indicating whether to use same color for error bars as markers for center.

kw_default property

Default keyword arguments for plotting (read-only)

marker property

Get the marker style for the center points if show_center is True, otherwise '' is returned (read-only).

err property

Get separated error lengths as 2D array. First row contains the lower errors, the second row contains the upper errors.

transform(feature_data, target_data)

Perform the transformation on the target data and return the transformed data.

PARAMETER DESCRIPTION
feature_data

Base location (offset) of feature axis coming from feature_grouped generator.

TYPE: float | int

target_data

Feature grouped target data used for transformation, coming from feature_grouped generator.

TYPE: pandas Series

RETURNS DESCRIPTION
data

The transformed data source for the plot.

TYPE: pandas DataFrame