Skip to content

Violine

daspi.plotlib.plotter.Violine(source, target, feature='', width=CATEGORY.FEATURE_SPACE, margin=0, fill=True, agreements=DEFAULT.AGREEMENTS, target_on_y=True, color=None, ax=None, visible_spines=None, hide_axis=None, **kwds)

Bases: GaussianKDE

Class for creating violine plotters.

This violin plot is composed of a double-sided Gaussian kernel density estimate. The width of the violin is stretched to fill the available width.

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

feature

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

TYPE: str DEFAULT: ''

width

Width of the violine, by default CATEGORY.FEATURE_SPACE.

TYPE: float DEFAULT: FEATURE_SPACE

margin

Margin for the sequence as factor of data range (max - min ). If margin is 0, The two ends of the estimated density curve then show the minimum and maximum value. Default is 0.

TYPE: float DEFAULT: 0

fill

Flag whether to fill in the curves, by default True

TYPE: bool DEFAULT: True

agreements

Specifies the tolerated process variation for calculating quantiles. These quantiles are used to represent the filled area with different opacity, thus highlighting the quantiles.If you want the filled area to be uniform without highlighting the quantiles, provide an empty tuple. This argument is only taken into account if fill is set to True. The agreements can be either integers or floats, determining the process variation tolerance in the following ways: - If integers, the quantiles are determined using the normal distribution (agreement * σ), e.g., agreement = 6 covers ~99.75% of the data. - If floats, values must be between 0 and 1, interpreted as acceptable proportions for the quantiles, e.g., 0.9973 corresponds to ~6σ. - If empty tuple, the filled area is uniform without highlighting the quantiles.

Default is DEFAULT.AGREEMENTS = (2, 4, 6), corresponding to (±1σ, ±2σ, ±3σ).

TYPE: Tuple[float, ...] or Tuple[int, ...] DEFAULT: AGREEMENTS

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

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 Violine

fig, ax = plt.subplots()
df = pd.DataFrame(dict(
    x = ['first'] * 50 + ['second'] * 50 + ['third'] * 50,
    y = (
        list(np.random.normal(loc=3, scale=1, size=50))
        + list(np.random.normal(loc=4, scale=1, size=50))
        + list(np.random.normal(loc=2, scale=1, size=50)))))
violine = Violine(
    source=df, target='y', feature='x', fill=True, margin=0.3, 
    agreements=(), ax=ax)
violine()
violine.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

df = pd.DataFrame(dict(
    x = ['first'] * 50 + ['second'] * 50 + ['third'] * 50,
    y = (
        list(np.random.normal(loc=3, scale=1, size=50))
        + list(np.random.normal(loc=4, scale=1, size=50))
        + list(np.random.normal(loc=2, scale=1, size=50)))))
chart = dsp.SingleChart(
        source=df,
        target='y',
        feature='x',
        categorical_feature=True, # neded to label the feature tick labels
    ).plot(
        dsp.Violine,
        fill=False,
        margin=0.3
    ).label() # neded to label the feature tick labels

kw_default property

Default keyword arguments for plotting (read-only)