%f — fractional seconds (milliseconds)¶
The new %f pattern formats the millisecond component of a datetime, zero-padded to 3 digits (e.g. 007, 123).
In [1]:
import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
In [2]:
df = pd.DataFrame({
't': pd.date_range('2025-06-01 12:00:00', periods=12, freq='117ms'),
})
df['value'] = range(len(df))
df
Out[2]:
On the axis¶
In [3]:
# Milliseconds only
ggplot(df, aes('t', 'value')) + geom_point() + ggsize(700, 250) \
+ scale_x_datetime(format='%f')
Out[3]:
In [4]:
# Seconds + milliseconds
ggplot(df, aes('t', 'value')) + geom_point() + ggsize(700, 250) \
+ scale_x_datetime(format='%S.%f')
Out[4]:
In [5]:
# Full ISO-like timestamp with milliseconds
ggplot(df, aes('t', 'value')) + geom_point() + ggsize(700, 250) \
+ scale_x_datetime(format='%Y-%m-%dT%H:%M:%S.%f')
Out[5]:
In tooltips¶
In [6]:
ggplot(df, aes('t', 'value')) + ggsize(700, 250) \
+ geom_point(tooltips=layer_tooltips()
.format('^x', '%H:%M:%S.%f')
.line('t|^x')
.line('value|^y')) \
+ scale_x_datetime(format='%S.%f')
Out[6]: