petab.visualize

Visualize

PEtab comes with visualization functionality. Those need to be imported via import petab.visualize.

class petab.visualize.DataProvider(exp_conditions: pandas.core.frame.DataFrame, measurements_data: Optional[pandas.core.frame.DataFrame] = None, simulations_data: Optional[pandas.core.frame.DataFrame] = None)[source]

Bases: object

Handles data selection.

_get_independent_var_values(data_df: pandas.core.frame.DataFrame, dataplot: petab.visualize.plotting.DataPlot) Tuple[numpy.ndarray, str, pandas.core.series.Series][source]

Get independent variable values.

Parameters
  • data_df – A pandas data frame to subset, can be from measurement file or simulation file.

  • dataplot – Data plot visualization settings.

Returns

  • col_name_unique – A name of the column from Measurement (Simulation) table, which specifies independent variable values (depends on the xValues entry of visualization specification). Possible values:

    • TIME (independent variable values will be taken from the TIME column of Measurement (Simulation) table)

    • SIMULATION_CONDITION_ID (independent variable values will be taken from one of the columns of Condition table)

  • uni_condition_id – Time points or contains all unique condition IDs which should be plotted together as one dataplot. Independent variable values will be collected for these conditions

  • conditions_ – An independent variable values or None for the BarPlot case possible values: time points, None, vales of independent variable (Parameter or Species, specified in the xValues entry of visualization specification) for each condition_id in uni_condition_id

static _matches_plot_spec(df: pandas.core.frame.DataFrame, plot_spec: petab.visualize.plotting.DataPlot, dataset_id) pandas.core.series.Series[source]

Construct an index for subsetting of the dataframe according to what is specified in plot_spec.

Parameters
  • df – A pandas data frame to subset, can be from measurement file or simulation file.

  • plot_spec – A visualization spec from the visualization file.

Returns

  • Boolean series that can be used for subsetting of the passed

  • dataframe

get_data_series(data_df: pandas.core.frame.DataFrame, data_col: str, dataplot: petab.visualize.plotting.DataPlot, provided_noise: bool) petab.visualize.plotting.DataSeries[source]

Get data to plot from measurement or simulation DataFrame.

Parameters
  • data_df (measurement or simulation DataFrame) –

  • data_col (data column, i.e. 'measurement' or 'simulation') –

  • dataplot (visualization specification) –

  • provided_noise – True if numeric values for the noise level are provided in the data table

Returns

Return type

Data to plot

get_data_to_plot(dataplot: petab.visualize.plotting.DataPlot, provided_noise: bool) Tuple[petab.visualize.plotting.DataSeries, petab.visualize.plotting.DataSeries][source]

Get data to plot.

Parameters
  • dataplot (visualization specification) –

  • provided_noise – True if numeric values for the noise level are provided in the measurement table

Returns

  • measurements_to_plot,

  • simulations_to_plot

class petab.visualize.Figure(subplots: Optional[List[petab.visualize.plotting.Subplot]] = None, size: Tuple = (20, 15), title: Optional[Tuple] = None)[source]

Bases: object

Visualization specification of a figure.

Contains information regarding how data should be visualized.

add_subplot(subplot: petab.visualize.plotting.Subplot) None[source]

Add subplot.

Parameters

subplot – Subplot visualization settings.

save_to_tsv(output_file_path: str = 'visuSpec.tsv') None[source]

Save full Visualization specification table.

Note that datasetId column in the resulting table might have been generated even though datasetId column in Measurement table is missing or is different. Please, correct it manually.

Parameters

output_file_path – File path to which the generated visualization specification is saved.

set_axes_limits(xlim: Optional[Tuple[Optional[numbers.Real], Optional[numbers.Real]]] = None, ylim: Optional[Tuple[Optional[numbers.Real], Optional[numbers.Real]]] = None) None[source]

Set axes limits for all subplots. If xlim or ylim or any of the tuple items is None, corresponding limit is left unchanged.

Parameters
  • xlim – X axis limits.

  • ylim – Y axis limits.

class petab.visualize.MPLPlotter(figure: petab.visualize.plotting.Figure, data_provider: petab.visualize.plotting.DataProvider)[source]

Bases: petab.visualize.plotter.Plotter

Matplotlib wrapper

static _square_plot_equal_ranges(ax: matplotlib.pyplot.Axes, lim: Optional[Union[List, Tuple]] = None) matplotlib.pyplot.Axes[source]

Square plot with equal range for scatter plots.

Returns

Return type

Updated axis object.

generate_barplot(ax: matplotlib.pyplot.Axes, dataplot: petab.visualize.plotting.DataPlot, plotTypeData: str) None[source]

Generate barplot.

Parameters
  • ax – Axis object.

  • dataplot – Visualization settings for the plot.

  • plotTypeData – Specifies how replicates should be handled.

generate_figure(subplot_dir: Optional[str] = None) Optional[Dict[str, matplotlib.axes._subplots.AxesSubplot]][source]

Generate the full figure based on the markup in the figure attribute.

Parameters

subplot_dir – A path to the folder where single subplots should be saved. PlotIDs will be taken as file names.

Returns

  • ax – Axis object of the created plot.

  • None – In case subplots are saved to file.

generate_lineplot(ax: matplotlib.pyplot.Axes, dataplot: petab.visualize.plotting.DataPlot, plotTypeData: str) None[source]

Generate lineplot.

It is possible to plot only data or only simulation or both.

Parameters
  • ax – Axis object.

  • dataplot – Visualization settings for the plot.

  • plotTypeData – Specifies how replicates should be handled.

generate_scatterplot(ax: matplotlib.pyplot.Axes, dataplot: petab.visualize.plotting.DataPlot, plotTypeData: str) None[source]

Generate scatterplot.

Parameters
  • ax – Axis object.

  • dataplot – Visualization settings for the plot.

  • plotTypeData – Specifies how replicates should be handled.

generate_subplot(ax, subplot: petab.visualize.plotting.Subplot) None[source]

Generate subplot based on markup provided by subplot.

Parameters
  • ax – Axis object.

  • subplot – Subplot visualization settings.

petab.visualize.plot_measurements_by_observable(data_file_path: str, condition_file_path: str, plotted_noise: Optional[str] = 'MeanAndSD') Optional[Union[Dict[str, matplotlib.axes._subplots.AxesSubplot], np.ndarray[plt.Subplot]]][source]

plot measurement data grouped by observable ID. A simple wrapper around the more complex function plot_data_and_simulation.

Parameters
  • data_file_path – file path of measurement data

  • condition_file_path – file path of condition file

  • plotted_noise – String indicating how noise should be visualized: [‘MeanAndSD’ (default), ‘MeanAndSEM’, ‘replicate’, ‘provided’]

Returns

ax

Return type

axis of figures

petab.visualize.plot_petab_problem(petab_problem: petab.problem.Problem, sim_data: Optional[Union[str, pandas.core.frame.DataFrame]] = None, dataset_id_list: Optional[List[List[str]]] = None, sim_cond_id_list: Optional[List[List[str]]] = None, sim_cond_num_list: Optional[List[List[int]]] = None, observable_id_list: Optional[List[List[str]]] = None, observable_num_list: Optional[List[List[int]]] = None, plotted_noise: Optional[str] = 'MeanAndSD') Optional[Union[Dict[str, matplotlib.axes._subplots.AxesSubplot], np.ndarray[plt.Subplot]]][source]

Visualization using petab problem. For documentation, see function plot_data_and_simulation()

petab.visualize.plot_problem(petab_problem: petab.problem.Problem, simulations_df: Optional[Union[str, pandas.core.frame.DataFrame]] = None, grouping_list: Optional[List[List[str]]] = None, group_by: str = 'observable', plotted_noise: str = 'MeanAndSD', subplot_dir: Optional[str] = None, plotter_type: str = 'mpl') Optional[Dict[str, matplotlib.axes._subplots.AxesSubplot]][source]

Visualization using petab problem. If Visualization table is part of the petab_problem, it will be used for visualization. Otherwise, grouping_list will be used. If neither Visualization table nor grouping_list are available, measurements (simulations) will be grouped by observable, i.e. all measurements for each observable will be visualized on one plot.

Parameters
  • petab_problem – A PEtab problem

  • simulations_df – A simulation DataFrame in the PEtab format or path to the simulation output data file.

  • grouping_list – A list of lists. Each sublist corresponds to a plot, each subplot contains the Ids of datasets or observables or simulation conditions for this plot.

  • group_by – Possible values: ‘dataset’, ‘observable’, ‘simulation’

  • plotted_noise – A string indicating how noise should be visualized: [‘MeanAndSD’ (default), ‘MeanAndSEM’, ‘replicate’, ‘provided’]

  • subplot_dir – A string which is taken as path to the folder where single subplots should be saved. PlotIDs will be taken as file names.

  • plotter_type – Specifies which library should be used for plot generation. Currently, only matplotlib is supported

Returns

  • ax (Axis object of the created plot.)

  • None (In case subplots are saved to a file.)

petab.visualize.plot_with_vis_spec(vis_spec_df, conditions_df: Union[str, pandas.core.frame.DataFrame], measurements_df: Optional[Union[str, pandas.core.frame.DataFrame]] = None, simulations_df: Optional[Union[str, pandas.core.frame.DataFrame]] = None, subplot_dir: Optional[str] = None, plotter_type: str = 'mpl') Optional[Dict[str, matplotlib.axes._subplots.AxesSubplot]][source]

Plot measurements and/or simulations. Specification of the visualization routines is provided in visualization table.

Parameters
  • vis_spec_df (visualization table) –

  • conditions_df – A condition DataFrame in the PEtab format or path to the condition file.

  • measurements_df – A measurement DataFrame in the PEtab format or path to the data file.

  • simulations_df – A simulation DataFrame in the PEtab format or path to the simulation output data file.

  • subplot_dir – A path to the folder where single subplots should be saved. PlotIDs will be taken as file names.

  • plotter_type – Specifies which library should be used for plot generation. Currently, only matplotlib is supported.

Returns

  • ax (Axis object of the created plot.)

  • None (In case subplots are saved to a file.)

petab.visualize.plot_without_vis_spec(conditions_df: Union[str, pandas.core.frame.DataFrame], grouping_list: Optional[List[List[str]]] = None, group_by: str = 'observable', measurements_df: Optional[Union[str, pandas.core.frame.DataFrame]] = None, simulations_df: Optional[Union[str, pandas.core.frame.DataFrame]] = None, plotted_noise: str = 'MeanAndSD', subplot_dir: Optional[str] = None, plotter_type: str = 'mpl') Optional[Dict[str, matplotlib.axes._subplots.AxesSubplot]][source]

Plot measurements and/or simulations. What exactly should be plotted is specified in a grouping_list. If grouping list is not provided, measurements (simulations) will be grouped by observable, i.e. all measurements for each observable will be visualized on one plot.

Parameters
  • grouping_list – A list of lists. Each sublist corresponds to a plot, each subplot contains the Ids of datasets or observables or simulation conditions for this plot.

  • group_by – Grouping type. Possible values: ‘dataset’, ‘observable’, ‘simulation’

  • conditions_df – A condition DataFrame in the PEtab format or path to the condition file.

  • measurements_df – A measurement DataFrame in the PEtab format or path to the data file.

  • simulations_df – A simulation DataFrame in the PEtab format or path to the simulation output data file.

  • plotted_noise – A string indicating how noise should be visualized: [‘MeanAndSD’ (default), ‘MeanAndSEM’, ‘replicate’, ‘provided’]

  • subplot_dir – A path to the folder where single subplots should be saved. PlotIDs will be taken as file names.

  • plotter_type – Specifies which library should be used for plot generation. Currently, only matplotlib is supported

Returns

  • ax (Axis object of the created plot.)

  • None (In case subplots are saved to a file.)

petab.visualize.save_vis_spec(exp_data: Union[str, pandas.core.frame.DataFrame], exp_conditions: Union[str, pandas.core.frame.DataFrame], vis_spec: Optional[Union[str, pandas.core.frame.DataFrame]] = None, dataset_id_list: Optional[List[List[str]]] = None, sim_cond_id_list: Optional[List[List[str]]] = None, sim_cond_num_list: Optional[List[List[int]]] = None, observable_id_list: Optional[List[List[str]]] = None, observable_num_list: Optional[List[List[int]]] = None, plotted_noise: Optional[str] = 'MeanAndSD', output_file_path: str = 'visuSpec.tsv')[source]

Generate and save visualization specification to a file. If vis_spec is provided, the missing columns will be added.

Parameters
  • exp_data – Measurement DataFrame in the PEtab format or path to the data file.

  • exp_conditions – Condition DataFrame in the PEtab format or path to the condition file.

  • vis_spec – Visualization specification DataFrame in the PEtab format or path to visualization file.

  • dataset_id_list – A list of lists. Each sublist corresponds to a plot, each subplot contains the datasetIds for this plot. Only to be used if no visualization file was available.

  • sim_cond_id_list – A list of lists. Each sublist corresponds to a plot, each subplot contains the simulationConditionIds for this plot. Only to be used if no visualization file was available.

  • sim_cond_num_list – A list of lists. Each sublist corresponds to a plot, each subplot contains the numbers corresponding to the simulationConditionIds for this plot. Only to be used if no visualization file was available.

  • observable_id_list – A list of lists. Each sublist corresponds to a plot, each subplot contains the observableIds for this plot. Only to be used if no visualization file was available.

  • observable_num_list – A list of lists. Each sublist corresponds to a plot, each subplot contains the numbers corresponding to the observableIds for this plot. Only to be used if no visualization file was available.

  • plotted_noise – String indicating how noise should be visualized: [‘MeanAndSD’ (default), ‘MeanAndSEM’, ‘replicate’, ‘provided’]

  • output_file_path – File path to which the generated visualization specification is saved.

Modules

petab.visualize.data_overview

Functions for creating an overview report of a PEtab problem

petab.visualize.helper_functions

This file should contain the functions, which PEtab internally needs for plotting, but which are not meant to be used by non-developers and should hence not be directly visible/usable when using import petab.visualize.

petab.visualize.plot_data_and_simulation

Functions for plotting PEtab measurement files and simulation results in the same format.

petab.visualize.plotter

PEtab visualization plotter classes

petab.visualize.plotting

PEtab visualization data selection and visualization settings classes

petab.visualize.plotting_config

Plotting config.