Skip to content

Bivariate univariate charts

daspi.plotlib.precast.BivariateUnivariateCharts(source, target, feature, hue='', dodge_univariates=False, categorical_feature_univariates=False, ratios=[3, 1], stretch_figsize=False, colors=())

Bases: JointChart

Provides a set of charts for visualizing the relationship between a target variable and a feature variable.

This class prepares a grid for drawing a bivariate plot with marginal univariate plots: - Bottom left there is a large square axis for the bivariate diagram. For example, use a LinearRegressionLine plotter to show the dependence of the target variable on the feature variable. - Top left there is a small square axis for the univariate plot of the feature variable. - Bottom right there is a small square axis for the univariate plot of the target variable. - Top right there is a small square axis hidden as soon a plot is done.

PARAMETER DESCRIPTION
source

The source data.

TYPE: DataFrame

target

The target (dependant) variable.

TYPE: str

feature

The feature (independant) variable.

TYPE: str

hue

The hue variable.

TYPE: str DEFAULT: ''

dodge_univariates

Whether to dodge the univariate plots, by default False.

TYPE: bool DEFAULT: False

categorical_feature_univariates

Whether to treat the feature variable for univariate charts as categorical, by default False.

TYPE: bool DEFAULT: False

ratios

The ratios of the bivariate axes height to the univariate axes height, by default [4, 1].

TYPE: List[float] DEFAULT: [3, 1]

stretch_figsize

If True, the height and width of the figure are stretched based on the number rows and columns in the axes grid. If a float is provided, the figure size is stretched by the given factor. If a tuple of two floats is provided, the figure size is stretched by the given factors for the x and y axis, respectively. by default False.

TYPE: bool | float | Tuple[float, float] DEFAULT: False

colors

Tuple of unique colors used for hue categories as hex or str. If not provided, the default colors will be used, by default ().

TYPE: Tuple[str, ...] DEFAULT: ()

Examples:

import daspi as dsp

df = dsp.load_dataset('painkillers-dissolution')
hue = 'brand'
n_groups = df.groupby(hue).ngroups
chart = dsp.BivariateUnivariateCharts(
        source=df,
        target='dissolution',
        feature='temperature',
        hue=hue,
        dodge_univariates=True,
    ).plot_univariates(
        dsp.MeanTest, n_groups=n_groups
    ).plot_univariates(
        dsp.QuantileBoxes, strategy='data'
    ).plot_bivariate(
        dsp.LinearRegressionLine, show_fit_ci=True
    ).label(
        fig_title='Regression and distribution analysis',
        sub_title='Painkillers dissolution time vs. temperature',
        feature_label='Water temperature (°C)',
        target_label='Dissolution time (s)',
        axes_titles=('95 % Bonferroni confidence interval of mean', '', '', ''),
        info=True
    )

BivariateUnivariateChartsDocstringExample

Information about which distribution is used to calculate the quantile boxes can be obtained as follows:

brands = (brand for brand in df[hue].unique().tolist()*2)
for plot in chart.plots:
    if isinstance(plot, dsp.QuantileBoxes):
        print(f'{next(brands)} {plot.target}: {plot.estimation.dist.dist_name}')

hidden_ax property

Get the top right axis (read-only).

univariate_axs property

Get the univariate axes (read-only).

bivariate_ax property

Get the bivariate axis (read-only).

hide_top_right_ax()

Hides the top right axis if it is not already hidden.

plot_univariates(plotter, *, kw_call={}, kw_where={}, **kwds)

Plots the univariate plots on the top left and bottom right axes.

PARAMETER DESCRIPTION
plotter

The plotter to use for the univariate plots.

TYPE: Type[Plotter]

kw_call

Additional keyword arguments for the plotter call method.

TYPE: Dict[str, Any] DEFAULT: {}

kw_where

Additional keyword arguments for the where method used to filter the data.

TYPE: Dict[str, Any] DEFAULT: {}

**kwds

Additional keyword arguments to be passed to the super plot method.

DEFAULT: {}

RETURNS DESCRIPTION
Self

The BivariateUnivariateCharts instance, for method chaining.

plot_bivariate(plotter, *, kw_call={}, kw_where={}, **kwds)

Plots the bivariate plot on the bottom left axis.

PARAMETER DESCRIPTION
plotter

The plotter to use for the univariate plots.

TYPE: Type[Plotter]

kw_call

Additional keyword arguments for the plotter call method.

TYPE: Dict[str, Any] DEFAULT: {}

kw_where

Additional keyword arguments for the where method used to filter the data.

TYPE: Dict[str, Any] DEFAULT: {}

**kwds

Additional keyword arguments to be passed to the super plot method.

DEFAULT: {}

RETURNS DESCRIPTION
Self

The BivariateUnivariateCharts instance, for method chaining.

label(*, fig_title='', sub_title='', feature_label='', target_label='', info=False, axes_titles=(), rows=(), cols=(), row_title='', col_title='')

Add labels and titles to the chart.

This method sets various labels and titles for the chart, including figure title, subplot title, axis labels, row and column titles, and additional information.

PARAMETER DESCRIPTION
fig_title

The main title for the entire figure, by default ''.

TYPE: str DEFAULT: ''

sub_title

The subtitle for the entire figure, by default ''.

TYPE: str DEFAULT: ''

feature_label

The label for the feature variable (x-axis), by default ''. If set to True, the feature variable name will be used. If set to False or None, no label will be added.

TYPE: str | bool | None DEFAULT: ''

target_label

The label for the target variable (y-axis), by default ''. If set to True, the target variable name will be used. If set to False or None, no label will be added.

TYPE: str | bool | None DEFAULT: ''

info

Additional information to display on the chart. If True, the date and user information will be automatically added at the lower left corner of the figure. If a string is provided, it will be shown next to the date and user, separated by a comma. By default, no additional information is displayed.

TYPE: bool | str DEFAULT: False

axes_titles

Title for each Axes, by default ()

TYPE: Tuple[str, ...] DEFAULT: ()

rows

The row labels of the figure, by default ().

TYPE: Tuple[str, ...] DEFAULT: ()

cols

The column labels of the figure, by default ().

TYPE: Tuple[str, ...] DEFAULT: ()

row_title

The title of the rows, by default ''.

TYPE: str DEFAULT: ''

col_title

The title of the columns, by default ''.

TYPE: str DEFAULT: ''

RETURNS DESCRIPTION
Self

The BivariateUnivariateCharts instance, for method chaining.

Notes

This method allows customization of chart labels and titles to enhance readability and provide context for the visualized data.