import pandas as pd
import hvplot.pandas
import geoviews as gv
import holoviews as hv
from bokeh.models import HoverTool
hv.extension("bokeh")
df = pd.read_html(
"https://mesonet.agron.iastate.edu/sites/networks.php?station=ORD&network=IL_ASOS"
)[1]
# make snake case
df.columns = df.columns.str.lower().str.replace(" ", "_")
# make a new column with the url to the windrose
df["url"] = [
f"https://mesonet.agron.iastate.edu/onsite/windrose/IL_ASOS/{stid}/{stid}_yearly.png"
for stid in df["id"]
]
# add some HTML to the hover tooltip
hover_tool = HoverTool(
tooltips="""
<div>
<img
src="@{url}" height="500" alt="@{url}"
></img>
</div>
"""
)
map = df.hvplot.points(
"longitude1",
"latitude1",
hover_cols=["url"], # be sure to list the columns you want to show in the hover
geo=True,
size=150,
width=1500,
height=1000,
).opts(tools=[hover_tool]) # override the tools to include the hover tool
# overlay the map
states = gv.feature.states(fill_alpha=0)
map * states
104. Want to show an image upon hovering?
104. Want to show an image upon hovering?
104. Want to show an image upon hovering?
Hover tooltips are not limited to text; they can include images too!
Simply format the image URL or encode as base64, write HTML, and add to hvplot!
Unfamiliar with HTML? Try asking ChatGPT for help!
#python #dataviz #holoviews #bokeh