diff --git a/animatplot/animation.py b/animatplot/animation.py index 24f847a..ce19522 100644 --- a/animatplot/animation.py +++ b/animatplot/animation.py @@ -1,6 +1,8 @@ from matplotlib.animation import FuncAnimation, PillowWriter from matplotlib.widgets import Button, Slider import matplotlib.pyplot as plt +import numpy as np + from animatplot import Timeline @@ -95,7 +97,7 @@ def pause(event): self._pause ^= True self.button.on_clicked(pause) - def timeline_slider(self, text='Time', ax=None, valfmt='%1.2f', color=None): + def timeline_slider(self, text='Time', ax=None, valfmt=None, color=None): """Creates a timeline slider. Parameters @@ -106,7 +108,7 @@ def timeline_slider(self, text='Time', ax=None, valfmt='%1.2f', color=None): The matplotlib axes to attach the slider to. valfmt : str, optional a format specifier used to print the time - Defaults to '%1.2f' + Defaults to '%s' for datetime64, timedelta64 and '%1.2f' otherwise. color : The color of the slider. """ @@ -119,6 +121,13 @@ def timeline_slider(self, text='Time', ax=None, valfmt='%1.2f', color=None): else: self.slider_ax = ax + if valfmt is None: + if (np.issubdtype(self.timeline.t.dtype, np.datetime64) + or np.issubdtype(self.timeline.t.dtype, np.timedelta64)): + valfmt = '%s' + else: + valfmt = '%1.2f' + if self.timeline.log: valfmt = '$10^{%s}$' % valfmt