From 1bd35a09256cf426e01f9143d17d5dedfb1cfef7 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 1 Jan 2018 15:13:35 +0800 Subject: clusters/mergertree: import matplotlib only when used In this way to avoid dependency on matplotlib. Also add print messages. --- fg21sim/extragalactic/clusters/mergertree.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'fg21sim/extragalactic/clusters') diff --git a/fg21sim/extragalactic/clusters/mergertree.py b/fg21sim/extragalactic/clusters/mergertree.py index 9d5361a..0e2a164 100644 --- a/fg21sim/extragalactic/clusters/mergertree.py +++ b/fg21sim/extragalactic/clusters/mergertree.py @@ -10,10 +10,6 @@ import os import pickle import logging -from matplotlib.figure import Figure -from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas - - logger = logging.getLogger(__name__) @@ -147,9 +143,14 @@ def plot_mtree(mtree, outfile, figsize=(12, 8)): _plot(tree.main, ax) _plot(tree.sub, ax) + # Import matplotlib when needed + from matplotlib.figure import Figure + from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas + fig = Figure(figsize=figsize) canvas = FigureCanvas(fig) ax = fig.add_subplot(1, 1, 1) + print("Plotting merger tree, may take a while ...") _plot(mtree, ax=ax) ax.set_xlabel("Cosmic time [Gyr]") ax.set_ylabel("Mass [Msun]") @@ -157,3 +158,4 @@ def plot_mtree(mtree, outfile, figsize=(12, 8)): ax.set_ylim((0, mtree.data["mass"])) fig.tight_layout() canvas.print_figure(outfile) + print("Saved plot to file: %s" % outfile) -- cgit v1.2.2