I'm trying to add a label or hover column to the points in a scatter plot, but to no avail.
For use as example data:
import pandas as pd
import holoviews as hv
import hvplot.pandas
df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\t')
df.query("year == 1966").hvplot.scatter(x="gdp", y="unem")
results in the picture below. If I hover over this item I cannot see, which country is represented by the dot (which makes it rather useless). I could use the additional keyword color="country"
in the scatterplot call. This would lead to an additional legend (which could be turned off) and the value country: countryname is added to the hover field.
Is there an option that just adds the column to my hover without adding a legend and changing the color?
You can use keyword hover_cols to add additional columns to your hover.
Documentation: https://hvplot.holoviz.org/user_guide/Customization.html
hover_cols (default=[]): list or str
Additional columns to add to the hover tool or 'all' which will includes all columns (including indexes if use_index is True).
So in your example if you would like to add specific columns to your hover:
# use keyword hover_cols to add additional columns when hovering
df.hvplot.scatter(x="gdp", y="unem", hover_cols=['country', 'year'])
Or if you want to include all additional columns to your hover:
df.hvplot.scatter(x="gdp", y="unem", hover_cols='all')
Or if you want to include all columns to hover, but not the index:
df.hvplot.scatter(x="gdp", y="unem", hover_cols='all', use_index=False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With