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:
|
target
|
Column name of the target variable for the plot.
TYPE:
|
feature
|
Column name of the feature variable for the plot, by default ''.
TYPE:
|
width
|
Width of the violine, by default CATEGORY.FEATURE_SPACE.
TYPE:
|
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:
|
fill
|
Flag whether to fill in the curves, by default True
TYPE:
|
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
TYPE:
|
target_on_y
|
Flag indicating whether the target variable is plotted on the y-axis, by default True.
TYPE:
|
color
|
Color to be used to draw the artists. If None, the first color is taken from the color cycle, by default None.
TYPE:
|
ax
|
The axes object for the plot. If None, the current axes is
fetched using
TYPE:
|
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:
|
hide_axis
|
Specifies which axes should be hidden. If None, both axes are displayed. Defaults to None.
TYPE:
|
**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)