%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]:
t value
0 2025-06-01 12:00:00.000 0
1 2025-06-01 12:00:00.117 1
2 2025-06-01 12:00:00.234 2
3 2025-06-01 12:00:00.351 3
4 2025-06-01 12:00:00.468 4
5 2025-06-01 12:00:00.585 5
6 2025-06-01 12:00:00.702 6
7 2025-06-01 12:00:00.819 7
8 2025-06-01 12:00:00.936 8
9 2025-06-01 12:00:01.053 9
10 2025-06-01 12:00:01.170 10
11 2025-06-01 12:00:01.287 11

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]: