break parts in tracepot into subroutines for readability
import matplotlib
-matplotlib.use('TkAgg')
+matplotlib.use('TkAgg') # see: https://matplotlib.org/faq/usage_faq.html#what-is-a-backend
import matplotlib.pyplot as plt
import numpy as np
@@ -18,12 +18,9 @@ def traceplot(trace: sample_types, labels: List[str] = None, ax: Any = None, x0:
data = [make_1d(v) for v in trace[label]]
ax[index][0].set_title(label)
+ ax[index][0].plot(__discrete_xaxis(ax[index][0], x0, len(data)), data)
- x = range(x0, x0 + len(data))
- ax[index][0].set_xticks(x)
- ax[index][0].plot(x, data)
-
- plt.pause(0.1)
+ __pause_for_crude_animation()
return ax
@@ -33,3 +30,13 @@ def make_1d(a: numpy_types) -> numpy_types:
# collapse array in row-major (C-style) order
# see: https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flatten.html
return a.flatten(order='C')
+
+
+def __discrete_xaxis(ax: Any, x0: int, n: int) -> range:
+ x = range(x0, x0 + n)
+ ax.set_xticks(x)
+ return x
+
+
+def __pause_for_crude_animation():
+ plt.pause(0.1)
