Long waiting commit

This commit is contained in:
Eric Teunis de Boone 2023-03-07 11:29:40 +01:00
parent cca2488480
commit 3df5748bd7
4 changed files with 55 additions and 21 deletions

Binary file not shown.

View file

@ -12,13 +12,18 @@ import scipy.signal as sig
### Functions ### Functions
def plot_signal( ax, t, t_edge, s_edge, name=None, box_kw={'hatch': '/'}, line_kw={}, annotate_t_edge=True,**plot_kw): def plot_signal( ax, t, t_edge, s_edge, name=None, box_kw={'hatch': '/'}, line_kw={}, annotate_t_edge=True, divide_s_edge=False,**plot_kw):
""" """
Plot a signal directly on an axis. Plot a signal directly on an axis.
Uses t_edge to trigger height Uses t_edge to trigger height
""" """
lower = (t > t_edge) if divide_s_edge:
upper = (t > t_edge + s_edge) lower = (t > t_edge - s_edge/2)
upper = (t > t_edge + s_edge/2)
else:
lower = (t > t_edge)
upper = (t > t_edge + s_edge)
# merge dictionaries correctly # merge dictionaries correctly
line_kw = { **plot_kw, **line_kw } line_kw = { **plot_kw, **line_kw }
@ -35,7 +40,6 @@ def plot_signal( ax, t, t_edge, s_edge, name=None, box_kw={'hatch': '/'}, line_k
l2 = ax.plot(t, upper, **line_kw) l2 = ax.plot(t, upper, **line_kw)
# plot the shaded box of width t_sigma # plot the shaded box of width t_sigma
l3 = ax.fill_between(t, upper, lower, **box_kw) l3 = ax.fill_between(t, upper, lower, **box_kw)
# annotations # annotations
@ -45,12 +49,15 @@ def plot_signal( ax, t, t_edge, s_edge, name=None, box_kw={'hatch': '/'}, line_k
y = 1 y = 1
ax.annotate("$t_\mathrm{{{}}}$".format(name), ax.annotate("$t_\mathrm{{{}}}$".format(name),
xy=(t_edge, y), xytext=(t_edge-3, y), xy=(t_edge, y), xytext=(t_edge-3, y),
va='top', ha='center' va='bottom', ha='center'
) )
# annotate s_edge # annotate s_edge
y = 0.3 y = 0.3
annotate_width(ax, "$\sigma_\mathrm{{{}}}$".format(name), t_edge, t_edge+s_edge, y) if divide_s_edge:
annotate_width(ax, "$\sigma_\mathrm{{{}}}$".format(name), t_edge-s_edge/2, t_edge+s_edge/2, y)
else:
annotate_width(ax, "$\sigma_\mathrm{{{}}}$".format(name), t_edge, t_edge+s_edge, y)
return [l, l2, l3] return [l, l2, l3]
@ -88,7 +95,7 @@ def annotate_width(ax, name, x1, x2, y, text_kw={}, arrow_kw={}):
## Main ## Main
def main(): def main(ref=(10,5), A=(40,10), B=(70,12) ):
""" """
Create a figure with two signals at times t1 and t2 (accuracy s1, s2) Create a figure with two signals at times t1 and t2 (accuracy s1, s2)
as compared to a reference timer tr (sr), with annotations. as compared to a reference timer tr (sr), with annotations.
@ -96,24 +103,21 @@ def main():
t = np.linspace(0, 100, 1e3) t = np.linspace(0, 100, 1e3)
t_A = 40 t_A, s_A = A
t_B = 70 t_B, s_B = B
t_ref = 10 t_ref, s_ref = ref
s_A = 10
s_B = 10
s_ref = 5
box_kw = { box_kw = {
"alpha": 0.3, "alpha": 0.6,
"hatch": '\\', "hatch": '\\',
} }
line_kw = { line_kw = {
} }
vline_kw = { vline_kw = {
"linestyle": '--', "linestyle": (0,(4,2)),
"color": "k", "color": "k",
"alpha":0.8,
} }
fig, axs = plt.subplots(3,1,sharex=True, gridspec_kw={'hspace': 0}); fig, axs = plt.subplots(3,1,sharex=True, gridspec_kw={'hspace': 0});
@ -122,10 +126,14 @@ def main():
axs[-1].set_xticks([]) axs[-1].set_xticks([])
axs[-1].set_xticklabels([]) axs[-1].set_xticklabels([])
for ax in axs: for ax in axs:
ax.set_ylim(-0.2, 1.2) ax.set_ylim(-0.25, 1.25)
ax.set_yticks([]) ax.set_yticks([])
ax.set_yticklabels([]) ax.set_yticklabels([])
ax.grid() ax.grid()
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
# Create the plots # Create the plots
i = -1 i = -1
@ -133,20 +141,20 @@ def main():
# Signal A # Signal A
i+=1 i+=1
y = 0.6 y = 0.6
axs[i].set_ylabel("Signal A") axs[i].set_ylabel("Signal A", rotation=0)
plot_diff_time(axs[i], "$t_\\mathrm{A}}$", t_ref, t_A, y, vline_kw=vline_kw) plot_diff_time(axs[i], "$t_\\mathrm{A}}$", t_ref, t_A, y, vline_kw=vline_kw)
plot_signal(axs[i], t, t_A, s_A, name="A", box_kw=box_kw, line_kw=line_kw, annotate_t_edge=False) plot_signal(axs[i], t, t_A, s_A, name="A", box_kw=box_kw, line_kw=line_kw, annotate_t_edge=False)
# Reference # Reference
i+=1 i+=1
axs[i].set_ylabel("Reference") axs[i].set_ylabel("Reference", rotation=0)
axs[i].axvline(t_ref, **vline_kw) axs[i].axvline(t_ref, **vline_kw)
plot_signal(axs[i], t, t_ref, s_ref, name="ref", box_kw=box_kw, line_kw=line_kw, color='g') plot_signal(axs[i], t, t_ref, s_ref, name="ref", box_kw=box_kw, line_kw=line_kw, color='g')
plot_diff_time(axs[i], "$t_\\mathrm{C}$", t_A, t_B, 0.3, vline_kw=vline_kw) plot_diff_time(axs[i], "$t_\\mathrm{C}$", t_A, t_B, 0.3, vline_kw=vline_kw)
# Signal B # Signal B
i+=1 i+=1
axs[i].set_ylabel("Signal B") axs[i].set_ylabel("Signal B", rotation=0)
plot_diff_time(axs[i], "$t_\\mathrm{B}}$", t_ref, t_B, y, vline_kw=vline_kw) plot_diff_time(axs[i], "$t_\\mathrm{B}}$", t_ref, t_B, y, vline_kw=vline_kw)
plot_signal(axs[i], t, t_B, s_B, name="B", box_kw=box_kw, line_kw=line_kw, color='purple', annotate_t_edge=False) plot_signal(axs[i], t, t_B, s_B, name="B", box_kw=box_kw, line_kw=line_kw, color='purple', annotate_t_edge=False)
@ -170,7 +178,8 @@ if __name__ == "__main__":
fig, _ = main() fig, _ = main()
if args.fname is not None: if args.fname is not None:
plt.savefig(args.fname) plt.tight_layout()
plt.savefig(args.fname, transparent=True)
else: else:
plt.show() plt.show()

View file

@ -0,0 +1,24 @@
# vim:ft=make
-include config.mk
.PHONY: all clean dist-clean
### Variables
MAIN_SRC ?= main.tex
TEXENGINE ?= latexmk --pdf
MAIN_TARGET = $(patsubst %.tex,%.pdf,$(MAIN_SRC))
### Targets
all: $(MAIN_TARGET)
dist: all clean
$(MAIN_TARGET): $(MAIN_SRC)
$(TEXENGINE) $^
dist-clean: clean
@rm -vf *.pdf *.eps *.dvi *.ps
clean:
@rm -vf *.dat *.log *.out *.aux *.nav *.snm *.toc *.vrb *~ *.fls *.fdb_latexmk *-blx.bib *.bbl *.blg *.run.xml

View file

@ -0,0 +1 @@
MAIN_SRC=2022-12-15_CRHEP.tex