From b02d768bdd545ddb74a4e122652d276b5cd16ec4 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 17 Jul 2023 21:20:16 +0200 Subject: [PATCH] Make validate_visualization_df work without matplotlib installation (#215) Only import plotting functions in `petab.visualize` if matplotlib is installed. Closes #212 Co-authored-by: Dilan Pathirana <59329744+dilpath@users.noreply.github.com> --- petab/visualize/__init__.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/petab/visualize/__init__.py b/petab/visualize/__init__.py index 70bb2ecf..60c5a327 100644 --- a/petab/visualize/__init__.py +++ b/petab/visualize/__init__.py @@ -6,24 +6,32 @@ ``import petab.visualize``. """ +import importlib.util -from .plot_data_and_simulation import ( - plot_without_vis_spec, - plot_with_vis_spec, - plot_problem, -) +mpl_spec = importlib.util.find_spec("matplotlib") -from .plot_residuals import plot_goodness_of_fit, plot_residuals_vs_simulation -from .plotter import MPLPlotter from .plotting import DataProvider, Figure __all__ = [ - "plot_without_vis_spec", - "plot_with_vis_spec", - "plot_problem", - "plot_goodness_of_fit", - "plot_residuals_vs_simulation", - "MPLPlotter", "DataProvider", "Figure" ] + +if mpl_spec is not None: + from .plot_data_and_simulation import ( + plot_without_vis_spec, + plot_with_vis_spec, + plot_problem, + ) + + from .plot_residuals import plot_goodness_of_fit, plot_residuals_vs_simulation + from .plotter import MPLPlotter + + __all__.extend([ + "plot_without_vis_spec", + "plot_with_vis_spec", + "plot_problem", + "plot_goodness_of_fit", + "plot_residuals_vs_simulation", + "MPLPlotter", + ])