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:
|
target
|
The target (dependant) variable.
TYPE:
|
feature
|
The feature (independant) variable.
TYPE:
|
hue
|
The hue variable.
TYPE:
|
dodge_univariates
|
Whether to dodge the univariate plots, by default False.
TYPE:
|
categorical_feature_univariates
|
Whether to treat the feature variable for univariate charts as categorical, by default False.
TYPE:
|
ratios
|
The ratios of the bivariate axes height to the univariate axes height, by default [4, 1].
TYPE:
|
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:
|
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:
|
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
)

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:
|
kw_call
|
Additional keyword arguments for the plotter call method.
TYPE:
|
kw_where
|
Additional keyword arguments for the where method used to filter the data.
TYPE:
|
**kwds
|
Additional keyword arguments to be passed to the super plot method.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The |
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:
|
kw_call
|
Additional keyword arguments for the plotter call method.
TYPE:
|
kw_where
|
Additional keyword arguments for the where method used to filter the data.
TYPE:
|
**kwds
|
Additional keyword arguments to be passed to the super plot method.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The |
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:
|
sub_title
|
The subtitle for the entire figure, by default ''.
TYPE:
|
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:
|
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:
|
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:
|
axes_titles
|
Title for each Axes, by default ()
TYPE:
|
rows
|
The row labels of the figure, by default ().
TYPE:
|
cols
|
The column labels of the figure, by default ().
TYPE:
|
row_title
|
The title of the rows, by default ''.
TYPE:
|
col_title
|
The title of the columns, by default ''.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The |
Notes
This method allows customization of chart labels and titles to enhance readability and provide context for the visualized data.