From 2f99a2ea14c6484cd2ff7b113a31cd1bef3be631 Mon Sep 17 00:00:00 2001 From: Joris Snellenburg Date: Sun, 25 Oct 2020 14:03:38 +0100 Subject: [PATCH] changed use of split lin-log axis to symlog --- pyglotaran_extras/plotting/plot_overview.py | 8 +-- pyglotaran_extras/plotting/plot_residual.py | 4 +- pyglotaran_extras/plotting/plot_svd.py | 14 ++++-- pyglotaran_extras/plotting/plot_traces.py | 54 ++------------------- 4 files changed, 21 insertions(+), 59 deletions(-) diff --git a/pyglotaran_extras/plotting/plot_overview.py b/pyglotaran_extras/plotting/plot_overview.py index 45cf5bcc..2879f50e 100644 --- a/pyglotaran_extras/plotting/plot_overview.py +++ b/pyglotaran_extras/plotting/plot_overview.py @@ -14,7 +14,7 @@ from .plot_residual import plot_residual -def plot_overview(result, center_λ=None, linlog=True, linrange=(-1, 1)): +def plot_overview(result, center_λ=None, linlog=True, linthresh=1): res = load_data(result) @@ -43,10 +43,10 @@ def plot_overview(result, center_λ=None, linlog=True, linrange=(-1, 1)): traces_shifted = traces.assign_coords(time=times_shifted) # First and second row: concentrations - SAS/EAS - DAS - plot_traces(res, ax[0, 0], center_λ, linlog=linlog, linrange=linrange) + plot_traces(res, ax[0, 0], center_λ, linlog=linlog, linthresh=linthresh) plot_spectra(res, ax[0:2, 1:3]) - plot_svd(res, ax[2:4, 0:3]) - plot_residual(res, ax[1, 0]) + plot_svd(res, ax[2:4, 0:3], linlog=linlog, linthresh=linthresh) + plot_residual(res, ax[1, 0], linlog=linlog, linthresh=linthresh) plot_style.set_default_colors() plot_style.set_default_fontsize() plt.rc("axes", prop_cycle=plot_style.cycler) diff --git a/pyglotaran_extras/plotting/plot_residual.py b/pyglotaran_extras/plotting/plot_residual.py index 0529f402..94da6c4e 100644 --- a/pyglotaran_extras/plotting/plot_residual.py +++ b/pyglotaran_extras/plotting/plot_residual.py @@ -1,10 +1,12 @@ import matplotlib.pyplot as plt -def plot_residual(res, ax): +def plot_residual(res, ax, linlog=False, linthresh=1): if min(res.data.shape) < 5: res.data.plot(x="time", ax=ax) else: res.data.plot(x="time", ax=ax, add_colorbar=False) + if linlog: + ax.set_xscale("symlog", linthresh=linthresh) plt.draw() plt.pause(0.001) diff --git a/pyglotaran_extras/plotting/plot_svd.py b/pyglotaran_extras/plotting/plot_svd.py index 51bfbacd..7110545a 100644 --- a/pyglotaran_extras/plotting/plot_svd.py +++ b/pyglotaran_extras/plotting/plot_svd.py @@ -2,24 +2,26 @@ import numpy as np -def plot_svd(res, axes): - plot_lsv_residual(res, axes[0, 0]) +def plot_svd(res, axes, linlog=False, linthresh=1): + plot_lsv_residual(res, axes[0, 0], linlog=linlog, linthresh=linthresh) plot_rsv_residual(res, axes[0, 1]) plot_sv_residual(res, axes[0, 2]) - plot_lsv_data(res, axes[1, 0]) + plot_lsv_data(res, axes[1, 0], linlog=linlog, linthresh=linthresh) plot_rsv_data(res, axes[1, 1]) plot_sv_data(res, axes[1, 2]) plt.draw() plt.pause(0.001) -def plot_lsv_data(res, ax, indices=range(4)): +def plot_lsv_data(res, ax, indices=range(4), linlog=False, linthresh=1): """ Plot left singular vectors (time) of the data matrix """ dLSV = res.data_left_singular_vectors dLSV.isel(left_singular_value_index=indices[0 : len(dLSV)]).plot.line( x="time", ax=ax ) ax.set_title("data. LSV") + if linlog: + ax.set_xscale("symlog", linthresh=linthresh) def plot_rsv_data(res, ax, indices=range(4)): @@ -40,7 +42,7 @@ def plot_sv_data(res, ax, indices=range(10)): ax.set_title("data. log(SV)") -def plot_lsv_residual(res, ax, indices=range(2), label="residual"): +def plot_lsv_residual(res, ax, indices=range(2), label="residual", linlog=False, linthresh=1): """ Plot left singular vectors (time) of the residual matrix """ if "weighted_residual_left_singular_vectors" in res: rLSV = res.weighted_residual_left_singular_vectors @@ -50,6 +52,8 @@ def plot_lsv_residual(res, ax, indices=range(2), label="residual"): x="time", ax=ax ) ax.set_title("res. LSV") + if linlog: + ax.set_xscale("symlog", linthresh=linthresh) def plot_rsv_residual(res, ax, indices=range(2)): diff --git a/pyglotaran_extras/plotting/plot_traces.py b/pyglotaran_extras/plotting/plot_traces.py index 09cf6d2c..47737536 100644 --- a/pyglotaran_extras/plotting/plot_traces.py +++ b/pyglotaran_extras/plotting/plot_traces.py @@ -31,62 +31,18 @@ def calculate_x_ranges(res, linrange): pass -def plot_traces(res, ax, center_λ, linlog=False, linrange=(-1, 1)): +def plot_traces(res, ax, center_λ, linlog=False, linthresh=1, linscale=1): traces = get_shifted_traces(res, center_λ) plot_style = PlotStyle() plt.rc("axes", prop_cycle=plot_style.cycler) - if not linlog: - if "spectral" in traces.coords: + if "spectral" in traces.coords: traces.sel(spectral=center_λ, method="nearest").plot.line(x="time", ax=ax) - else: - traces.plot.line(x="time", ax=ax) else: - # Setting up code for Linear-Logariuthmic time axis - axLin = ax - divider = make_axes_locatable(axLin) - ncolors = len(plot_style._color_codes) + traces.plot.line(x="time", ax=ax) - # Plotting Linear Part. - if "spectral" in traces.coords: - traces.sel(spectral=center_λ, method="nearest").plot.line( - x="time", ax=axLin - ) - else: - traces.plot.line(x="time", ax=axLin) - axLin.set_xscale("linear") - axLin.set_xlim(linrange) - # axLin.xaxis.set_major_locator(MaxNLocator(prune="upper")) + if linlog: + ax.set_xscale("symlog", linthresh=linthresh,linscale=linscale) - axLin.spines["right"].set_visible(False) - axLin.yaxis.set_ticks_position("left") - axLin.yaxis.set_visible(True) - axLin.set_prop_cycle(plot_style.cycler) - - # Plotting Logarithmic Part. - axLog = divider.append_axes( - "right", size="60%", pad=0, sharey=axLin, prop_cycle=plot_style.cycler - ) - axLog.set_xscale("log") - xlim_max = 10 ** math.ceil(math.log10(res.time.values.max())) - axLog.set_xlim((linrange[1], xlim_max)) - axLog.xaxis.set_major_locator(MaxNLocator(prune="lower", nbins=2)) - # axLog.xaxis.set_major_locator(MultipleLocator(linrange[1])) - if "spectral" in traces.coords: - traces.sel(spectral=center_λ, method="nearest").plot.line( - x="time", ax=axLog - ) - else: - traces.plot.line(x="time", ax=axLog) - axLog.get_yaxis().set_visible(False) - axLog.get_legend().remove() - axLog.set_title("") - axLog.set_ylabel("") - axLog.set_xlabel("") - - axLog.yaxis.set_tick_params(which="minor", right="off") - axLog.spines["left"].set_visible(False) - - plt.setp(axLog.get_xticklabels(minor=False), visible=True) plt.draw() plt.pause(0.005)