# Show hoverinfo over fill area of polygon in scatter trace

**URL:** <https://community.plotly.com/t/show-hoverinfo-over-fill-area-of-polygon-in-scatter-trace/48534>\
**Category:** 📊 Plotly Python\
**Created:** [December 28, 2020, 5:53pm UTC](https://community.plotly.com/t/show-hoverinfo-over-fill-area-of-polygon-in-scatter-trace/48534 "2020-12-28T17:53:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkapitan](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/dkapitan/32/2739_2.png) [@dkapitan](https://community.plotly.com/u/dkapitan)\
**Post date:** [December 28, 2020, 5:53pm UTC](https://community.plotly.com/t/show-hoverinfo-over-fill-area-of-polygon-in-scatter-trace/48534/1 "2020-12-28T17:53:43Z")

</div>

Similar to [this question](https://community.plotly.com/t/hoverinfo-over-fill-area-of-polygon/44986), I would like to have hoverinfo over polygons with scatter traces.

My use case is that I want to build a [comet chart](https://www.zanarmstrong.com/infovisresearch) which I have previously [done in bokeh](https://github.com/dkapitan/comet-chart).

The [graphing library documentation](https://plotly.com/python/shapes/#adding-lines-and-polygons-to-figures) says it should be possible to add hoverinfo. However, I can’t get it to work. See the simple example below.

```auto
fig = go.Figure(
    go.Scatter(
        x=[0, 1, 2, 0, None, 0, 0.5, 0, 0],
        y=[0, 2, 0, 0, None, 1, 2, 2, 1],
        fill="toself",
        hoverinfo="all",
        hovertext=["triangle 1", "triangle 2"],
        mode='line'
    )
)
fig.show()

```

Is this at all possible?

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [December 29, 2020, 9:22pm UTC](https://community.plotly.com/t/show-hoverinfo-over-fill-area-of-polygon-in-scatter-trace/48534/2 "2020-12-29T21:22:16Z")

</div>

@dkapitan  
There is a scatter attribute `hoveron`. Unfortunately if you are setting `hoveron="fills"`, the hover over each triangle displays only the trace name.  
Hence this option is not a solution. You can define a dummy trace of type scatter, mode=“none”, that associates a string (text) to each triangle center of mass:

```auto
import plotly.graph_objects as go
import numpy as np
#define data fo your triangles:
x = np.array([0, 1, 2, None, 0, 0.5, 0, None, 0.5, 1.5, 1])
y = np.array([0, 2., 0, None, 1, 2, 2, None, 2.5, 2.5, 4])
#get the indices for None
I = np.where(x==None)[0]
J = np.where(y==None)[0]
X = []
Y = []
#calculate the centers of mass
for i, j in zip(I,J):
    X.append(np.mean(x[i-3:i]))
    Y.append(np.mean(y[i-3:i]))
X.append(np.mean(x[i+1:]))    
Y.append(np.mean(y[i+1:]))   

fig = go.Figure(
    go.Scatter(
        x=x,
        y=y,
        fill="toself",
        mode='none',
        hoverinfo='skip'
    )
)
fig.add_scatter(x=X, y=Y, 
                mode='none',
                showlegend=False,
                text=[f'triangle {k}' for k in range(1, len(I)+2)],
                hoverinfo='text')

```

---

<div class="post-metadata">

**Author:** ![dkapitan](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/dkapitan/32/2739_2.png) [@dkapitan](https://community.plotly.com/u/dkapitan)\
**Post date:** [December 29, 2020, 10:47pm UTC](https://community.plotly.com/t/show-hoverinfo-over-fill-area-of-polygon-in-scatter-trace/48534/3 "2020-12-29T22:47:07Z")

</div>

Thanks @empet, will give this a try!
