holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 402 forks source link

A better default formatting for timedelta in holomaps #4322

Open ahuang11 opened 4 years ago

ahuang11 commented 4 years ago

Nanoseconds isn't used too frequently I think.

import xarray as xr
import hvplot.xarray
ds = xr.tutorial.open_dataset('air_temperature')
ds.coords['timedelta'] = ds['time'] - ds['time'].isel(time=0)
ds = ds.swap_dims({'time': 'timedelta'})
ds.hvplot('lon', 'lat')

Or only holoviews:

import xarray as xr
import holoviews as hv
ds = xr.tutorial.open_dataset('air_temperature')
ds.coords['timedelta'] = ds['time'] - ds['time'].isel(time=0)
ds = ds.swap_dims({'time': 'timedelta'})
hv.Dataset(ds).to.image(['lon', 'lat'], ['air'], dynamic=True)

image

itsgifnotjiff commented 1 year ago

Same issue and I have a function that returns an hvplot so I do not have the option to manually set it. Has anyone found how to do it?

hoxbro commented 1 year ago

Nanoseconds are how the data is stored, which is why it is used for the title and the widget.

What is done behind the scenes is this: image

A workaround, for now, is just to set the title on the plot, which removes it from the title: image

A more advanced way is to convert the time delta to an int: (it is not perfect but it is a start)

import xarray as xr
import hvplot.xarray

ds = xr.tutorial.open_dataset('air_temperature')
ds.coords['time'] = (ds['time'] - ds['time'].isel(time=0)).values.astype("timedelta64[s]").astype(int)
ds.coords['time'].attrs["units"] = "seconds"

ds.hvplot('lon', 'lat')

image