holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.08k stars 105 forks source link

timedelta64[ns] axis tick formatting problem #488

Open zbarry opened 4 years ago

zbarry commented 4 years ago

ALL software version info

hvplot 0.6.0

Description of expected behavior and the observed behavior

It looks like tick formatting for time axes is not being applied for the first plot in a layout, only in subsequent ones:

import pandas as pd
import holoviews as hv
import hvplot.pandas
import numpy as np

hv.extension('bokeh')

time_end = 10
sampling_time = 0.2

timepoints = np.arange(0, time_end, sampling_time)

df = pd.DataFrame(dict(
    time=pd.to_timedelta(timepoints, 's'),
    value=np.sin(timepoints),
    value_2=timepoints,
))

(
    df.hvplot(x='time', y='value') 
    + df.hvplot(x='time', y='value_2')
)

image

philippjfr commented 4 years ago

Just as an initial guess I think the issue here might be that JS does not have sufficient integer precision to represent nanosecond datetimes so something is getting lost along the way.

zbarry commented 4 years ago

Ah, I see. Is there some other dtype you think I should try instead to represent time series data based on timedeltas?

jlstevens commented 4 years ago

If it is a precision issue in JS, then presumably this can can be reproduced with a pure Bokeh example?

philippjfr commented 3 years ago

Looking at this again I think this is just down to the fact that timedeltas aren't handled well.

douglas-raillard-arm commented 6 months ago

A similar issue affects polars (unsurprisingly since it converts to pandas first, and the pandas dtype ends up being timedelta64[ns] as well):

import polars as pl
df = pl.DataFrame(dict(a=list(range(10000)), b=list(range(10000))), schema=dict(a=pl.Duration('ns'), b=int))
df.plot.line('a', 'b')

So whoever takes on https://github.com/holoviz/holoviews/issues/5939 should ensure nanosecond works as well (and not rely on Python timedeltas: https://github.com/pola-rs/polars/issues/14695)

EDIT: updated the snippet to a more obvious example of truncation to microsecond.