plot_utils: move pre_plot_setup and post_plot_setup to plot_utils
I need it for plot_allfreqs() which is not an object inheriting from
ThermalBase
diff --git a/cr2/plot_utils.py b/cr2/plot_utils.py
index 4b4f163..da892ef 100644
--- a/cr2/plot_utils.py
+++ b/cr2/plot_utils.py
@@ -32,3 +32,34 @@
title = opt_title + " - " + title
return title
+
+def pre_plot_setup(width=None, height=None):
+ """initialize a figure
+
+ width and height are numbers, ylim is a tuple with min and max
+ values for the y axis. This function should be called before
+ any calls to plot()
+ """
+
+ set_plot_size(width, height)
+
+ _, ax = plt.subplots()
+
+ return ax
+
+def post_plot_setup(ax, title="", ylim=None):
+ """Set xlabel, title and ylim of the plot
+
+ This has to be called after calls to .plot()
+ """
+
+ plt.xlabel("Time")
+ if title:
+ plt.title(title)
+
+ if not ylim:
+ cur_ylim = ax.get_ylim()
+ ylim = (cur_ylim[0] - 0.1 * (cur_ylim[1] - cur_ylim[0]),
+ cur_ylim[1] + 0.1 * (cur_ylim[1] - cur_ylim[0]))
+
+ ax.set_ylim(ylim[0], ylim[1])