You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
add ability to hide missing data from hover tooltip #3515
I have a dataframe column with some missing values which I want to include in hover_data. Is it possible to show the column in the hover tooltip only if there's value for the currently hovered point? The current default behavior is to show col_name=%{customdata[0]} for missing values. I think it would be better to show nothing at all.
@janosh
I thought you want remove customdata just for this example, because here if you are dsiplaying fig.data[0], and fig.data[1] you'll see that in both cases the elements of customdata are all None:
I think that a solution is to convert customdata to strings, and set ' ', instead of None:
import numpy as np
import plotly.graph_objects as go
N=24
vals = np.random.randint(1000, 2001, N).astype(str)
#or vals = (7*np.random.rand(24)).astype(str)
I = np.random.randint(0, N, 12)
vals[I]=''
fig=go.Figure(go.Scatter(x=np.arange(0,N), y=4+5*np.random.rand(N), customdata=vals,
hovertemplate='vals: %{customdata}'))
fig.show()
Unfortunately we cannot access individual elements in customdata to set hovertemplate with an if else , depending on whether an element is ' ', or not.
Is there any other way to slove the problem? l have a stacked line graph with same question, some point missing value in stack and display %{customdata} in hover. i can not convert customdata to strings, and set ' ', in fact this point even not in my dataframe, just because other point in same stack it appeard lije this:
The last workaround, and generally filling a dataframe with a string, now throws an error in pandas, and will soon not be allowed, for columns with dtypes that are not strings (datetime, float, etc) I believe. That's just to say that a solution here soonish would be a big value add :)
I think my ideal preference as far as implementation goes would be to have a layout or trace setting where you could give a value for missing data, e.g. "-", and missing data would be sniffed using pd.isnull because things like NaT will be missed otherwise I think.
I appreciate the need, but realistically, our team isn't going to get to this in the plotting layer any time soon. We'd be happy to prioritize review of a community PR if someone wants to put one together. Thanks - @gvwilson
As of plotly.py v6.4.0, this situation is handled much better: In the case of missing data, a hyphen is displayed rather than the raw template string (implemented by plotly/plotly.js#7577 in plotly.js). So basically the behavior proposed by @alexscott-ff.
A different fallback string besides a hyphen can be used by setting the trace's hovertemplatefallback attribute.
I'll leave this issue open, though, since it's still not possible to hide the hovertext entry entirely when data is missing.
Activity
empet commentedon Dec 27, 2021
Commenting out these two lines
and/or just this one:
removes
pop:= %{customdata[0]}from tooltips.janosh commentedon Dec 27, 2021
@empet You misunderstood. I do want the population data in the tooltip, just not for points where that data is missing. The line
is just to simulate missing data.
empet commentedon Dec 27, 2021
@janosh
I thought you want remove customdata just for this example, because here if you are dsiplaying fig.data[0], and fig.data[1] you'll see that in both cases the elements of customdata are all None:
janosh commentedon Dec 27, 2021
I know. They're all
Nonebecause I was too lazy to only set the value for that point toNonewhich is being hovered in the screenshot.empet commentedon Dec 27, 2021
I think that a solution is to convert customdata to strings, and set
' ', instead of None:Unfortunately we cannot access individual elements in
customdatato sethovertemplatewith anif else, depending on whether an element is' ', or not.[-]Hide custom data from hover tooltip for missing data[/-][+]Hide missing data from hover tooltip[/+]krieg0102 commentedon Aug 18, 2022
Is there any other way to slove the problem? l have a stacked line graph with same question, some point missing value in stack and display

%{customdata}in hover. i can not convert customdata to strings, and set ' ', in fact this point even not in my dataframe, just because other point in same stack it appeard lije this:lijecaru commentedon Aug 18, 2022
Is there any development on this issue? I would also like my hovertip to skip that specific customdata if it's np.nan
yaelbh commentedon Aug 25, 2022
I also have the same problem. Will be nice if the package owners will give it high priority.
sarangof commentedon Mar 27, 2023
Ditto.
[-]Hide missing data from hover tooltip[/-][+]add ability to hide missing data from hover tooltip[/+]alexscott-ff commentedon Apr 11, 2025
The last workaround, and generally filling a dataframe with a string, now throws an error in pandas, and will soon not be allowed, for columns with dtypes that are not strings (datetime, float, etc) I believe. That's just to say that a solution here soonish would be a big value add :)
I think my ideal preference as far as implementation goes would be to have a layout or trace setting where you could give a value for missing data, e.g. "-", and missing data would be sniffed using
pd.isnullbecause things likeNaTwill be missed otherwise I think.gvwilson commentedon Apr 11, 2025
I appreciate the need, but realistically, our team isn't going to get to this in the plotting layer any time soon. We'd be happy to prioritize review of a community PR if someone wants to put one together. Thanks - @gvwilson
emilykl commentedon Aug 28, 2026
As of plotly.py v6.4.0, this situation is handled much better: In the case of missing data, a hyphen is displayed rather than the raw template string (implemented by plotly/plotly.js#7577 in plotly.js). So basically the behavior proposed by @alexscott-ff.
A different fallback string besides a hyphen can be used by setting the trace's
hovertemplatefallbackattribute.I'll leave this issue open, though, since it's still not possible to hide the hovertext entry entirely when data is missing.