Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Holoviews panels and axis sharing after plot update - datetime axis #7795

Open
1 task
mayonnaisecolouredbenz7 opened this issue Mar 19, 2025 · 2 comments
Open
1 task

Comments

@mayonnaisecolouredbenz7
Copy link
Contributor

mayonnaisecolouredbenz7 commented Mar 19, 2025

ALL software version info

panel==1.6.1

Software Version Info
holoviews==1.20.1
bokeh==3.6.3
hvplot==-0.11.2

Description of expected behavior and the observed behavior

When two or more holoviews plots are on the same page and the axes are linked. If you change the view (for example with mouse scroll) on one, then updated the data and the plots, it returns an error. Steps are as follows:

  • Show two holoviews panes
  • Scroll to changes axes limits, both adjust as expected
  • Refresh the data and update the plots.

Complete, minimal, self-contained example code that reproduces the issue

import panel as pn
import pandas as pd
import hvplot.pandas
import holoviews as hv
import numpy as np
pn.extension('tabulator',sizing_mode='stretch_width')
hv.extension('bokeh', theme='dark')


class MREViewer(pn.viewable.Viewer):

    plot1 = pn.pane.HoloViews(sizing_mode='stretch_width')
    plot2 = pn.pane.HoloViews(sizing_mode='stretch_width')
    reload_data_button = pn.widgets.Button(name='Reload Data')

    @pn.depends('reload_data_button.clicks', watch=True,on_init=True))
    def update_plots(self):
        dates = pd.date_range('2021-01-01', periods=365)
        data = pd.DataFrame({'Date': dates, 'Value': np.random.randn(365).cumsum()})

        new_plot1 = data.hvplot(x='Date', y='Value', title='Plot 1')
        new_plot2 = data.hvplot(x='Date', y='Value', title='Plot 2')
        self.plot1.object = new_plot1
        self.plot2.object = new_plot2

    def __panel__(self):
        # Include the reload_data_button in the layout
        layout = pn.Column(self.reload_data_button, self.plot1, self.plot2)
        return layout

app = MREViewer()
app.servable()

Stack traceback and/or browser JavaScript console output

message: Message 'PATCH-DOC' content: {'events': [{'kind': 'MessageSent', 'msg_type': 'bokeh_event', 'msg_data': {'type': 'event', 'name': 'button_click', 'values': {'type': 'map', 'entries': [['model', {'id': 'p7196'}]]}}}]}
error: UFuncTypeError(<ufunc 'greater'>, (<class 'numpy.dtypes.DateTime64DType'>, <class 'numpy.dtypes._PyFloatDType'>, None))
numpy.exceptions.DTypePromotionError: The DType <class 'numpy.dtypes.DateTime64DType'> could not be promoted by <class 'numpy.dtypes._PyFloatDType'>. This means that no common DType exists for the given inputs. For example they cannot be stored in a single array unless the dtype is object. The full list of DTypes is: (<class 'numpy.dtypes.DateTime64DType'>, <class 'numpy.dtypes._PyFloatDType'>)

The above exception was the direct cause of the following exception:

...

if axis.start > axis.end:
^^^^^^^^^^^^^^^^^^^^^
numpy._core._exceptions._UFuncNoLoopError: ufunc 'greater' did not contain a loop with signature matching types (<class 'numpy.dtypes.DateTime64DType'>, <class 'numpy.dtypes._PyFloatDType'>) -> None

Screenshots or screencasts of the bug in action

Image

Image

After reload data clicked
Image

Traceback shown above

  • I may be interested in making a pull request to address this
@mayonnaisecolouredbenz7
Copy link
Contributor Author

This is specific to the case when the x-axis is datetime. No issue with numerical axes.

@mayonnaisecolouredbenz7 mayonnaisecolouredbenz7 changed the title Holoviews panels and axis sharing after plot update Holoviews panels and axis sharing after plot update - datetime axis Mar 19, 2025
@mayonnaisecolouredbenz7
Copy link
Contributor Author

Using DynamicMap with bounded functions is a a workaround for this issue. Not sure if this stays as an issue or not however

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

pn.extension('tabulator', 'plotly', sizing_mode='stretch_width')
hv.extension('bokeh', theme='dark')


class MREViewer(pn.viewable.Viewer):

    reload_data_button = pn.widgets.Button(name='Reload Data')

    def update_plot1(self, event):
        dates = pd.date_range('2021-01-01', periods=365)
        data = pd.DataFrame(
            {'Date': dates, 'Value': np.random.randn(365).cumsum()})

        return hv.Curve(data).opts(responsive=True, framewise=True)

    def update_plot2(self, event):
        dates = pd.date_range('2021-01-01', periods=365)
        data = pd.DataFrame(
            {'Date': dates, 'Value': np.random.randn(365).cumsum()})

        return hv.Curve(data).opts(responsive=True, framewise=True)

    def __panel__(self):
        plot1 = hv.DynamicMap(
            pn.bind(self.update_plot1, self.reload_data_button))
        plot2 = hv.DynamicMap(
            pn.bind(self.update_plot2, self.reload_data_button))

        layout = pn.Column(self.reload_data_button, plot1, plot2)
        return layout


app = MREViewer()
app.servable()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant