use MaxNLocator instead for enforcing integer axis.
import matplotlib
matplotlib.use('TkAgg') # see: https://matplotlib.org/faq/usage_faq.html#what-is-a-backend
import matplotlib.pyplot as plt
+from matplotlib.ticker import MaxNLocator
import numpy as np
from keanu.vartypes import sample_types, numpy_types
@@ -27,7 +28,7 @@ def traceplot(trace: sample_types, labels: List[str] = None, ax: Any = None, x0:
data = [__make_1d(sample) for sample in trace[label]]
ax[index][0].set_title(label)
- ax[index][0].plot(__discrete_xaxis(ax[index][0], x0, len(data)), data)
+ ax[index][0].plot(__integer_xaxis(ax[index][0], x0, len(data)), data)
__pause_for_crude_animation()
@@ -51,9 +52,9 @@ def __make_1d(a: numpy_types) -> numpy_types:
return a.flatten(order='C')
-def __discrete_xaxis(ax: Any, x0: int, n: int) -> range:
+def __integer_xaxis(ax: Any, x0: int, n: int) -> range:
x = range(x0, x0 + n)
- ax.set_xticks(x)
+ ax.xaxis.set_major_locator(MaxNLocator(integer=True))
return x
