DensityCurve
DensityCurve
¶
Bases: SpreadOpacity, TransformPlotter
Base class for plotting a probability density curve along the feature axis.
This class holds all the logic shared by the density-curve
plotters (data grouping, optional quantile highlighting, filling
and drawing). Subclasses only need to implement :meth:estimate,
which computes the sequence of target values and the corresponding
density estimation for one feature group:
GaussianKDEestimates the density non-parametrically from the raw data and controls the curve width viamargin.FittedDensityfits (or assumes) a distribution according tostrategyand evaluates its PDF, controlling the curve width viaagreementsinstead ofmargin.
If cumulative is set to True, the cumulative distribution (CDF)
is plotted instead of the density (PDF). Subclasses may override
:meth:estimate_cumulative to compute the CDF directly (e.g. from
a fitted distribution's analytic cdf); by default it is derived
by numerically integrating :meth:estimate.
| 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 ''. Please note that this class is designed for univariate plots, so by default, all curves will be drawn on the same feature axis. If you want to draw curves on different feature axes, change the "ignore_feature" parameter to False and provide a feature column in the source DataFrame.
TYPE:
|
stretch
|
Factor by which the curve was stretched in height, by default 1.
TYPE:
|
height
|
Height of the density curve at its maximum. If None, it will be determined automatically, by default None.
TYPE:
|
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:
|
ignore_feature
|
Flag indicating whether the feature axis should be ignored. If True, all curves have base 0 on the feature axis, by default True
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. Has no
effect if
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:
|
strategy
|
Which strategy should be used to determine the quantiles used
for highlighting, see
TYPE:
|
possible_dists
|
Distributions to which the data may be subject, see
TYPE:
|
cumulative
|
If True, the cumulative distribution (CDF) is plotted instead of the density (PDF), by default False.
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:
|
n_points
|
Number of points the density estimation and sequence should have, by default KD_SEQUENCE_LEN (defined in constants.py).
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:
|
cumulative = cumulative
instance-attribute
¶
Flag whether the cumulative distribution (CDF) is plotted instead of the density (PDF).
n_points = n_points
instance-attribute
¶
Number of points that have the density estimation and its sequence.
margin = margin
instance-attribute
¶
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.
fill = fill
instance-attribute
¶
Flag whether to fill in the curves
kw_default
property
¶
Default keyword arguments for plotting (read-only)
height
property
¶
Height of the density curve at its maximum.
stretch
property
¶
Factor by which the curve was stretched in height
highlight_quantiles
property
¶
Flag indicating whether the quantiles should be highlighted.
Always False for cumulative curves: the area under a CDF has
no meaningful interpretation as probability mass (unlike a
PDF), so quantile fill bands would shade a large area for a
small probability range and be visually misleading.
estimate
¶
Compute the sequence of target values and the corresponding density estimation for one feature group. Must be implemented by subclasses.
| PARAMETER | DESCRIPTION |
|---|---|
feature_data
|
Base location (offset) of feature axis coming from
TYPE:
|
target_data
|
Feature grouped target data used for transformation,
coming from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
sequence
|
Data points at regular intervals used as target data.
TYPE:
|
estimation
|
Density estimation values used as feature data.
TYPE:
|
estimate_cumulative
¶
Compute the sequence of target values and the corresponding cumulative distribution (CDF) for one feature group.
The default implementation numerically integrates
:meth:estimate (trapezoidal rule) and rescales the result to
span from feature_data to feature_data + stretch (or
height). Subclasses may override this to compute the CDF
directly, e.g. from a fitted distribution's analytic cdf.
| PARAMETER | DESCRIPTION |
|---|---|
feature_data
|
Base location (offset) of feature axis coming from
TYPE:
|
target_data
|
Feature grouped target data used for transformation,
coming from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
sequence
|
Data points at regular intervals used as target data.
TYPE:
|
estimation
|
Cumulative distribution values used as feature data.
TYPE:
|
transform
¶
Perform the transformation on the target data by estimating
its density (or cumulative distribution, if cumulative is
True). To obtain a uniform curve, a sequence is generated
with a specific number of points in the same range (min to max)
as the target data.
| PARAMETER | DESCRIPTION |
|---|---|
feature_data
|
Base location (offset) of feature axis coming from
TYPE:
|
target_data
|
Feature grouped target data used for transformation,
coming from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
data
|
The transformed data source for the plot. Contains the generated sequence as target data and the estimation as feature data.
TYPE:
|