plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.
https://plotly.com/dash
MIT License
21.46k stars 2.07k forks source link

[BUG] Datetime axes don't work in dash when using datashader rasterize on a holoviews quadmesh/rasterplot #1678

Closed CP-Vub closed 3 months ago

CP-Vub commented 3 years ago

Context

dash                               1.20.0
dash-core-components               1.16.0
dash-html-components               1.1.3
dash-renderer                      1.9.1
dash-table                         4.11.3

Bug description

I have been trying out the new Holoviews integration with Dash as it finally offers a great native solution to use datashader. However, there seems to be a bug with datetime axes when combined with rasterize of datashader. E.g. when I visualize a rasterized quadmesh without a datetime x-axis, it works fine. When I replace the x-axis with datetimes, I get the following error :

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'

Expected behavior I expect the rasterized holoviews quadmesh to work with datetime axes and not just numeric-only axes.

MWE I made an MWE where X is a numeric-only x-axis and X_datetime is the datetime x-axis that causes the error.

# Imports
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

# Setup of X, Y and Z
# Normal numeric x-axis (this works when used in hv.QuadMesh)
X = np.logspace(1,5,100)
# Datetime x-axis (this causes the error)
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)
# Create the rasterized quadmesh
figure  = rasterize(hv.QuadMesh((X_datetime, Y, Z)),
                    dynamic=True,
                    width=50,
                    height=50
                    )
# Create the app
app = dash.Dash(__name__)
components = to_dash(app,[figure])
app.layout = html.Div(components.children)
if __name__ == "__main__":
    app.run_server(debug=True)
gvwilson commented 3 months ago

Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are most important to our community. If this issue is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. (Please note that we will give priority to reports that include a short reproducible example.) If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson