Skip to content

Commit

Permalink
changed use of split lin-log axis to symlog
Browse files Browse the repository at this point in the history
jsnel committed Oct 25, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 5558876 commit 2f99a2e
Showing 4 changed files with 21 additions and 59 deletions.
8 changes: 4 additions & 4 deletions pyglotaran_extras/plotting/plot_overview.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 3 additions & 1 deletion pyglotaran_extras/plotting/plot_residual.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 9 additions & 5 deletions pyglotaran_extras/plotting/plot_svd.py
Original file line number Diff line number Diff line change
@@ -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)):
54 changes: 5 additions & 49 deletions pyglotaran_extras/plotting/plot_traces.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2f99a2e

Please sign in to comment.