-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Support hover_cols with rasterize #1206
Comments
@ahuang11 I created the issue here |
Hi @balshersingh10, @hoxbro kindly worked out a solution you can find below. It leverages the new In general it's important to think about the displayed data when rasterizing a dataset. For color mapping, each pixel is an aggregation of the data points it contains, the default is a count, in your example as you set import datashader as ds
import holoviews as hv
import hvplot.pandas
import numpy as np
import pandas as pd
import panel as pn
from bokeh.models import HoverTool, CustomJSHover
from holoviews.operation.datashader import rasterize
# Create a dummy DataFrame
np.random.seed(0)
n = 10000 # number of points
df = pd.DataFrame(
{
"Longitude": np.random.uniform(-180, 180, n),
"Latitude": np.random.uniform(-90, 90, n),
"Timestamp": pd.date_range(start="2023-01-01", periods=n, freq="D"),
"Value": np.random.rand(n) * 100, # This will represent 'selected_col'
}
)
selected_col = "Value"
tile = hv.element.tiles.EsriNatGeo().opts(width=1000, height=650)
_hover_code = """
const projections = Bokeh.require("core/util/projections");
const {snap_x, snap_y} = special_vars
const coords = projections.wgs84_mercator.invert(snap_x, snap_y)
return "" + (coords[%d]).toFixed(4)
"""
_date_hover_code = """
let d = new Date(0)
d.setUTCSeconds(Math.floor(value / 1e9))
return d.toDateString()
"""
hover = HoverTool(
tooltips=[
("Timestamp", "@Timestamp{custom}"),
("(Longitude,Latitude)", "$x{custom}, $y{custom}"),
(selected_col, f"@image{{0.0}}"),
],
formatters={
"$x": CustomJSHover(code=_hover_code % 0),
"$y": CustomJSHover(code=_hover_code % 1),
"@Timestamp": CustomJSHover(code=_date_hover_code),
},
)
plot = df.hvplot.points("Longitude", "Latitude", hover_cols=['Value'], geo=True)
rplot = rasterize(plot, aggregator=ds.mean('Value'), selector=ds.max("Value"), dynamic=False).opts(
tools=[hover], cmap="Reds", colorbar=True
)
tile * rplot |
ALL software version info
Details
Description of expected behavior and the observed behavior
When hover tooltip is enabled, Timestamp not working. I discussed this issue in discourse, Andrew helped me to fix some things, still Timestamp is not working.
https://discourse.holoviz.org/t/how-to-set-up-hovertool-for-multiple-columns-with-hvplot/4294/16?u=balsher.singh
Complete, minimal, self-contained example code that reproduces the issue
Stack traceback and/or browser JavaScript console output
Screenshots or screencasts of the bug in action
The text was updated successfully, but these errors were encountered: