From 98acb07de08c953b3d4c41d0bb158c1b78f5d947 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich <yannick.ulrich@psi.ch> Date: Sun, 9 Feb 2020 21:12:37 +0100 Subject: [PATCH] 18a: abstracted twopanel plot in re #17 and towards #13 --- pymule/plot.py | 64 +++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/pymule/plot.py b/pymule/plot.py index e5cfbf1..c7aae30 100644 --- a/pymule/plot.py +++ b/pymule/plot.py @@ -52,46 +52,46 @@ def errorband(p, ax=None, underflow=False, overflow=False): return artist -def kplot(sigma, k, sigmar=[], kr=[], - labelx='x_e', - labelk="$K$", labelkr=None, - labelsigma=None, labelsigmar=None): - - if type(sigma) == np.ndarray: - sigma = [sigma] - if type(sigmar) == np.ndarray: - sigmar = [sigmar] - if type(k) == np.ndarray: - k = [k] - if type(kr) == np.ndarray: - kr = [kr] - - if labelsigma is None: - labelsigma = r"$\D\sigma\,/\,\D " + labelx + "$" - - fig, axs = plt.subplots(2, sharex=True, sharey=True, gridspec_kw={'hspace': 0}) - axs[1].set_xlabel("$"+labelx+"$") - - axs[0].set_ylabel(labelsigma) - for i in sigma: +def twopanel(labelx, + upleft=[], labupleft="", + downleft=[], labdownleft="", + upright=[], labupright="", + downright=[], labdownright=""): + + if type(upleft) == np.ndarray: + upleft = [upleft] + if type(upright) == np.ndarray: + upright = [upright] + if type(downleft) == np.ndarray: + downleft = [downleft] + if type(downright) == np.ndarray: + downright = [downright] + + fig, axs = plt.subplots( + 2, sharex=True, sharey=True, gridspec_kw={'hspace': 0} + ) + axs[1].set_xlabel(labelx) + + axs[0].set_ylabel(labupleft) + for i in upleft: errorband(i, ax=axs[0]) - if len(sigmar) > 0: + if len(upright) > 0: ax2 = axs[0].twinx() - if labelsigmar is not None: - ax2.set_ylabel(labelsigmar) - for i in sigmar: + if labupright is not None: + ax2.set_ylabel(labupright) + for i in upright: errorband(i, ax=ax2) - axs[1].set_ylabel(labelk) - for i in k: + axs[1].set_ylabel(labdownleft) + for i in downleft: errorband(i, ax=axs[1]) - if len(kr) > 0: + if len(downright) > 0: ax3 = axs[1].twinx() - if labelkr is not None: - ax3.set_ylabel(labelkr) - for i in kr: + if labdownright is not None: + ax3.set_ylabel(labdownright) + for i, c in downright: errorband(i, ax=ax3) return fig, axs -- GitLab