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", + ])