I have been trying out the new Holoviews integration with Dash as it finally offers a great native solution to use datashader for some of the plots in my dashboard. However, one issue I haven’t found a solution to (despite much googling) is the problem with datetime axes, particularly for Quadmeshes. When I visualize the rasterized quadmesh without a datetime x-axis, it works fine. When I replace the x-axis with datetimes, I always get the following error (no matter what formatting I try) :
Traceback (most recent call last):
File "MWE.py", line 36, in <module>
components = to_dash(app,
File "anaconda3\lib\site-packages\holoviews\plotting\plotly\dash.py", line 369, in to_dash
plot = PlotlyRenderer.get_plot(hvobj)
File "anaconda3\lib\site-packages\holoviews\plotting\renderer.py", line 243, in get_plot
plot.update(init_key)
File "anaconda3\lib\site-packages\holoviews\plotting\plot.py", line 982, in update
return self.initialize_plot()
File "anaconda3\lib\site-packages\holoviews\plotting\plotly\element.py", line 126, in initialize_plot
fig = self.generate_plot(self.keys[-1], ranges, is_geo=is_geo)
File "anaconda3\lib\site-packages\holoviews\plotting\plotly\element.py", line 181, in generate_plot
data = self.get_data(element, ranges, style, is_geo=is_geo)
File "anaconda3\lib\site-packages\holoviews\plotting\plotly\raster.py", line 44, in get_data
dx, dy = float(r-l)/nx, float(t-b)/ny
TypeError: float() argument must be a string or a number, not 'datetime.timedelta'
It seems like the combination of dash+rasterize does not like datetime axes, even though they are supported by regular holoviews+dash. I made an MWE to illustrate the issue:
import dash
import dash_html_components as html
import holoviews as hv
from holoviews.plotting.plotly.dash import to_dash
from holoviews.operation.datashader import rasterize
import numpy as np
import pandas as pd
# Normal numeric x-axis (this works when used in hv.QuadMesh)
X = np.logspace(1,5,100)
# Datetime x-axis
X_datetime = pd.date_range(start='1/1/2018', end='1/08/2018',periods=100)
Y = np.linspace(1,100,100)
Z = np.random.randn(100,100)
options = dict(cmap='jet',
colorbar=True,
height=600)
figure = rasterize(hv.QuadMesh((X_datetime, Y, Z)),
dynamic=True,
width=50,
height=50
)
figure = figure.opts(**options)
app = dash.Dash(__name__)
components = to_dash(app,
[figure],
reset_button=True)
app.layout = html.Div(components.children)
if __name__ == "__main__":
app.run_server(debug=True)
Is the possibility to have datetime axes in a rasterized holoviews chart simply not supported by the Plotly renderer, or am I doing something wrong here?
Thanks in advance!