Skip to content

Commit b02d768

Browse files
dweindldilpath
andauthored
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>
1 parent 25ee7aa commit b02d768

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

petab/visualize/__init__.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,32 @@
66
``import petab.visualize``.
77
88
"""
9+
import importlib.util
910

10-
from .plot_data_and_simulation import (
11-
plot_without_vis_spec,
12-
plot_with_vis_spec,
13-
plot_problem,
14-
)
11+
mpl_spec = importlib.util.find_spec("matplotlib")
1512

16-
from .plot_residuals import plot_goodness_of_fit, plot_residuals_vs_simulation
17-
from .plotter import MPLPlotter
1813
from .plotting import DataProvider, Figure
1914

2015
__all__ = [
21-
"plot_without_vis_spec",
22-
"plot_with_vis_spec",
23-
"plot_problem",
24-
"plot_goodness_of_fit",
25-
"plot_residuals_vs_simulation",
26-
"MPLPlotter",
2716
"DataProvider",
2817
"Figure"
2918
]
19+
20+
if mpl_spec is not None:
21+
from .plot_data_and_simulation import (
22+
plot_without_vis_spec,
23+
plot_with_vis_spec,
24+
plot_problem,
25+
)
26+
27+
from .plot_residuals import plot_goodness_of_fit, plot_residuals_vs_simulation
28+
from .plotter import MPLPlotter
29+
30+
__all__.extend([
31+
"plot_without_vis_spec",
32+
"plot_with_vis_spec",
33+
"plot_problem",
34+
"plot_goodness_of_fit",
35+
"plot_residuals_vs_simulation",
36+
"MPLPlotter",
37+
])

0 commit comments

Comments
 (0)