leaspy.io.logs.visualization

Submodules

Classes

Plotter

Class defining some plotting tools.

Plotting

Package Contents

class Plotter(output_path=None)[source]

Class defining some plotting tools.

Parameters:
output_pathstr, (optional)

Folder where plots will be saved. If None, default to current working directory.

Parameters:

output_path (Optional[str])

output_path = None
plt_show()[source]

Display the current matplotlib figure if self._show is True.

This method wraps matplotlib.pyplot.show using the internal flags _show and _block to control interactive plotting.

plot_mean_trajectory(model, *, n_pts=100, n_std_left=3, n_std_right=6, **kwargs)[source]

Plot the mean model trajectory.

Parameters:
modelMcmcSaemCompatibleModel or iterable of such

Model(s) to compute the mean trajectory for.

n_ptsint, optional

Number of timepoints to evaluate between the start and end. Default=100.

n_std_leftint, optional

How many standard deviations before the mean to plot. Default=3.

n_std_rightint, optional

How many standard deviations after the mean to plot. Default=6.

**kwargs
  • color : iterable of colors

  • title : str, plot title

  • save_as : str, filename to save the plot

Raises:
LeaspyInputError

If the model(s) is/are not initialized.

Parameters:
plot_mean_validity(model, results, **kwargs)[source]

Plot histogram of reparametrized times for all individuals.

Parameters:
modelMcmcSaemCompatibleModel

Fitted model providing tau_mean and tau_std.

resultsobject

Results containing data and individual_parameters with keys xi and tau.

**kwargs
  • save_as : str, filename to save the plot.

Parameters:

model (McmcSaemCompatibleModel)

Return type:

None

plot_patient_trajectory(model, results, indices, **kwargs)[source]

Plot observed data and reconstructed trajectory for one or more patients.

Parameters:
modelMcmcSaemCompatibleModel

Model to use for computing individual trajectories.

resultsobject

Results containing data and individual parameters.

indicesstr or list of int

Patient index/indices to plot.

**kwargs
  • ax : matplotlib axis to plot on.

  • color : iterable of colors.

  • title : str, plot title.

  • save_as : str, filename to save the plot.

Parameters:

model (McmcSaemCompatibleModel)

Return type:

None

plot_from_individual_parameters(model, indiv_parameters, timepoints, **kwargs)[source]

Plot a trajectory computed from given individual parameters.

Parameters:
modelMcmcSaemCompatibleModel

Model used to compute the trajectory.

indiv_parametersDictParamsTorch

Individual parameter dictionary.

timepointstorch.Tensor

Timepoints at which to compute the trajectory.

**kwargs
  • color : iterable of colors.

  • save_as : str, filename to save the plot.

Parameters:
Return type:

None

plot_distribution(results, parameter, cofactor=None, **kwargs)[source]

Plot histogram(s) of an estimated parameter distribution.

Parameters:
resultsobject

Results containing a get_parameter_distribution method.

parameterstr

Parameter name to plot.

cofactoroptional

Grouping variable; if given, plot separate histograms per group.

**kwargs
  • save_as : str, filename to save the plot.

Parameters:

parameter (str)

plot_correlation(results, parameter_1, parameter_2, cofactor=None, **kwargs)[source]

Plot scatter correlation between two parameters.

Parameters:
resultsobject

Results containing a get_parameter_distribution method.

parameter_1str

First parameter name.

parameter_2str

Second parameter name.

cofactoroptional

Grouping variable; if given, scatter different colors per group.

**kwargs
  • save_as : str, filename to save the plot.

plot_patients_mapped_on_mean_trajectory(model, results, *, n_std_left=2, n_std_right=4, n_pts=100)[source]

Plot observed patient values mapped onto the mean trajectory.

Parameters:
modelMcmcSaemCompatibleModel

Model used for computing mean and individual trajectories.

resultsobject

Results containing data and individual parameters.

n_std_leftint, optional

How many standard deviations before the mean to plot. Default=2.

n_std_rightint, optional

How many standard deviations after the mean to plot. Default=4.

n_ptsint, optional

Number of timepoints to evaluate. Default=100.

Parameters:
Return type:

None

classmethod plot_error(path, dataset, model, param_ind, colors=None, labels=None)[source]
Parameters:

model (McmcSaemCompatibleModel)

classmethod plot_patient_reconstructions(path, dataset, model, param_ind, *, max_patient_number=5, attribute_type=None)[source]
Parameters:
static plot_param_ind(path, param_ind)[source]
static plot_convergence_model_parameters(path, path_saveplot_1, path_saveplot_2, model)[source]
class Plotting(model, output_path='.', palette='tab10', max_colors=10)[source]

Deprecated since version 1.2.

Class defining some plotting tools.

Parameters:
modelBaseModel

The used model.

output_pathstr, (optional)

Folder where plots will be saved. If None, default to current working directory.

palettestr (palette name) or matplotlib.colors.Colormap (ListedColormap or LinearSegmentedColormap)

The palette to use.

max_colorsint > 0, optional (default, corresponding to model nb of features)

Only used if palette is a string

model
color_palette = None
standard_size = (8, 4)
linestyle
linewidth
alpha
output_path = '.'
set_palette(palette, max_colors=None)[source]

Set palette of plots

Parameters:
palettestr (palette name) or matplotlib.colors.Colormap (ListedColormap or LinearSegmentedColormap)

The palette to use.

max_colorsint > 0, optional (default, corresponding to model nb of features)

Only used if palette is a string

colors(at=None)[source]

Wrapper over color_palette iterator to get colors

Parameters:
atany legit color_palette arg (int, float or iterable of any of these) or None (default)

if None returns all colors of palette upto model dimension

Returns:
colorssingle color tuple (RGBA) or np.array of RGBA colors (number of colors x 4)
average_trajectory(**kwargs)[source]

Plot the population average trajectories. They are parametrized by the population parameters derived during the calibration.

Parameters:
**kwargs
  • alpha: float, default 0.6

    Matplotlib’s transparency option. Must be in [0, 1].

  • linestyle: {‘-’, ‘–’, ‘-.’, ‘:’, ‘’, (offset, on-off-seq), …}

    Matplotlib’s linestyle option.

  • linewidth: float

    Matplotlib’s linewidth option.

  • features: list[str]

    Name of features (if set it must be a subset of model features) Default: all model features.

  • colors: list[str]

    Contains matplotlib compatible colors. At least as many as number of features.

  • labels: list[str]

    Used to rename features in the plot. Exactly as many as number of features. Default: raw variable name of each feature

  • ax: matplotlib.axes.Axes

    Axes object to modify, instead of creating a new one.

  • figsize: tuple of int

    The figure’s size.

  • save_as: str, default None

    Path to save the figure.

  • title: str

  • n_tpts: int

    Number of timepoints in plot (default: 100)

  • n_std_left, n_std_right: float (default: 3 and 6 resp.)

    Time window around tau_mean, expressed as times of max(tau_std, 4)

Returns:
matplotlib.axes.Axes
patient_observations(data, patients_idx='all', individual_parameters=None, **kwargs)[source]

Plot patient observations

Parameters:
dataData
patients_idx‘all’ (default), str or list[str]

Patients to display (by their ID).

individual_parametersIndividualParameters or pandas.DataFrame (as may be output by ip.to_dataframe()) or dict (Pytorch ip format), optional

If not None, observations are plotted with respect to reparametrized ages.

patient_observations_reparametrized(data, individual_parameters, patients_idx='all', **kwargs)[source]

Plot patient observations (reparametrized ages)

patient_trajectories(data, individual_parameters, patients_idx='all', reparametrized_ages=False, **kwargs)[source]

Plot patient observations together with model individual reconstruction

Parameters:
dataData
individual_parametersIndividualParameters or pandas.DataFrame (as may be output by ip.to_dataframe()) or dict (Pytorch ip format)
patients_idx‘all’ (default), str or list[str]

Patients to display (by their ID).

reparametrized_agesbool (default False)

Should we plot trajectories in reparam age or not? to study source impact essentially

**kwargs

cf. _plot_model_trajectories() In particular, pass marker=None if you don’t want observations besides model