# Show name of shape on hover (or always visible)

**URL:** <https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353>\
**Category:** 📊 Plotly Python\
**Tags:** question\
**Created:** [August 25, 2022, 2:56pm UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353 "2022-08-25T14:56:09Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [August 25, 2022, 2:56pm UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/1 "2022-08-25T14:56:09Z")

</div>

Hi there,

I wonder if it is possible to show the name of a shape (annotation) on hover, or if this wasn’t possible, to show it always. I don’t understand the explanation in the help concerning the name parameter:

> **[Layout.shapes](https://plotly.com/python/reference/layout/shapes/)**
>
> Figure

Example:

```python
import plotly.graph_objects as go

# prepare data
data = go.Scatter(
    x=[1, 10], 
    y=[1, 10],
    mode='markers',
    marker={
        'size': 8,
        'symbol': 'circle-open',
    },
)

# create figure
fig = go.Figure(data=data)

# add shape
fig.add_shape(
    {
        'type':'rect', 
        'x0': 3, 'x1': 5, 
        'y0': 3, 'y1': 5, 
    },
    editable=True,
    name='shape_1',
)
fig.add_shape(
    {
        'type':'rect', 
        'x0': 8, 'x1': 9, 
        'y0': 8, 'y1': 9, 
    },
    editable=True,
    name='shape_2',
)

# show figure
fig.show()

```

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![akroma](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/akroma/32/20346_2.png) [@akroma](https://community.plotly.com/u/akroma)\
**Post date:** [August 25, 2022, 7:28pm UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/2 "2022-08-25T19:28:06Z")

</div>

Hey @AIMPED ,

I couldn’t find a hover option for shapes. But one option is that you can use go.scatter which supports hover.

```auto
import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Scatter(x=[3,5,5,3,3],
                         y=[3,3,1,1,3],
                         fill='toself',
                         fillcolor='yellow',
                         mode='lines',
                         name="Rectangle"
                         )
              )

fig.add_shape(type='rect',
              x0=6, x1= 10,
              y0=6, y1= 10,
              name="rectangle",
              fillcolor='red'
              )

fig.show()

```

 ![example_out](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/4/d/4d9611077ee4fdbf1913bb86a7d445bb7b624121.png)

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [August 26, 2022, 6:19am UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/3 "2022-08-26T06:19:57Z")

</div>

Hi @akroma ,

thanks for this idea, I have come across something similar while googling my “problem”. It`s a nice workaround which unfortunately I can’t use.

The shapes are actually created by the user in a Dash app as a annotation. They should be editable, i.e. the user should be able to change the size or position.

Do you by any chance know, what the name parameter of the layout.shapes is meant to be for?

---

<div class="post-metadata">

**Author:** ![akroma](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/akroma/32/20346_2.png) [@akroma](https://community.plotly.com/u/akroma)\
**Post date:** [August 26, 2022, 6:39am UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/4 "2022-08-26T06:39:28Z")

</div>

> The shapes are actually created by the user in a Dash app as a annotation. They should be editable, i.e. the user should be able to change the size or position.

I understand. Unfortunately I don’t know about the name parameter of the layout.shapes.

But I’ll try to come up with different solution.

---

<div class="post-metadata">

**Author:** ![alexcjohnson](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/alexcjohnson/32/614_2.png) [@alexcjohnson](https://community.plotly.com/u/alexcjohnson)\
**Post date:** [August 26, 2022, 3:11pm UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/5 "2022-08-26T15:11:04Z")

</div>

Yeah the name attribute for shapes is pretty arcane, we’ve probably never properly documented this but it’s a strange use case anyway. You can put a named shape in a graph template, then it will be drawn on any graph that uses this template but if you want to modify the shape you can make a new one in the graph with a `templateitemname` matching the `name` found in the template shape. There’s an example of this for annotations in our tests - we make a [watermark annotation](https://github.com/plotly/plotly.js/blob/8206eb50805b248327573b0ea8d2514c5375b06d/test/image/mocks/template.json#L57) and then draw [three copies in different sizes](https://github.com/plotly/plotly.js/blob/8206eb50805b248327573b0ea8d2514c5375b06d/test/image/mocks/template.json#L16-L18) - you can see the result [here](https://github.com/plotly/plotly.js/blob/master/test/image/baselines/template.png)

Hover on shapes has come up before - see [Hover & text on shapes · Issue #4780 · plotly/plotly.js · GitHub](https://github.com/plotly/plotly.js/issues/4780) - would be a great feature to add, hasn’t bubbled up in our queue yet but if anyone would like to work on it it probably wouldn’t be too difficult, we’d be happy to point you in the right direction. Or if you’re interested in sponsoring the work please reach out 🙂

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [August 31, 2022, 11:56am UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/6 "2022-08-31T11:56:10Z")

</div>

Hi @alexcjohnson ,

Thank’s for your answer and the examples of using the name attribute. Unfortunately I am just a Dash user and not a javascript developer so I can’t help creating this feature.

Once I decide how to solve this in my app, Ill post an answer here.

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [May 1, 2023, 7:22pm UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/7 "2023-05-01T19:22:16Z")

</div>

As promised, here is how I will do this in my app.

With the release of Plotly [5.14.0](https://community.plotly.com/t/dash-2-9-2-released-partial-property-updates-with-patch-duplicate-outputs-dcc-geolocation-scatter-group-attributes-and-more/72114) labels have been added to annotations.

> **[Shapes](https://plotly.com/python/shapes/?_gl=1*12a3ev8*_ga*MTMyMjk3MTQ3MC4xNjI5NjY5NjEy*_ga_6G7EE0JNSC*MTY4Mjk2Mzg5OS4zNDAuMS4xNjgyOTY4Mjk5LjAuMC4w#adding-text-labels-to-shapes)**
>
> Over 22 examples of Shapes including changing color, size, log axes, and more in Python.

These labels are always visible but I could imagine creating a ON/OFF switch for these labels by changing the text color of the label using a rgba string with opacity set to 0.

---

<div class="post-metadata">

**Author:** ![matan3](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@matan3](https://community.plotly.com/u/matan3)\
**Post date:** [April 6, 2024, 9:42pm UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/8 "2024-04-06T21:42:43Z")

</div>

This is a useful addition. But is there any option for showing text only when hovering the shape? that avoids having to fit the text to the shape, and avoids a cluttered view.

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [April 7, 2024, 7:58am UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/9 "2024-04-07T07:58:24Z")

</div>

Hey @matan3, there is no built-in functionality that I know of, unfortunately.

---

<div class="post-metadata">

**Author:** ![matan3](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@matan3](https://community.plotly.com/u/matan3)\
**Post date:** [April 7, 2024, 2:00pm UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/10 "2024-04-07T14:00:46Z")

</div>

That’s fine. It’s fine as is, and maybe one day …

---

<div class="post-metadata">

**Author:** ![matan3](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@matan3](https://community.plotly.com/u/matan3)\
**Post date:** [June 14, 2024, 8:17am UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/11 "2024-06-14T08:17:06Z")

</div>

Would a feature request on this be welcome? (showing text for a shape only on hover)

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [June 16, 2024, 9:07pm UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/12 "2024-06-16T21:07:02Z")

</div>

Hey @matan3, I’m pretty sure! @adamschroeder

---

<div class="post-metadata">

**Author:** ![matan3](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@matan3](https://community.plotly.com/u/matan3)\
**Post date:** [June 17, 2024, 6:27am UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/13 "2024-06-17T06:27:14Z")

</div>

> [@AIMPED](#):
>
> @adamschroeder

@adamschroeder Should that go on Github? Or is it frankly not inline with any feature trajectory or too much obviated by Dash? Speaking of Dash can we launch a dash server as a one-off or have a few of them running on different ports? Should one purchase a Dash license in all cases or is it only a certain enterprise context which makes a license necessary? sorry for the crossing topics.

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [June 17, 2024, 1:49pm UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/14 "2024-06-17T13:49:38Z")

</div>

hi @matan3  
Good question.I’ll talk to the team today about hover on shapes and get back to you.  
[Update: @matan3 can you please give a thumbs up to the [gitHub issue](https://github.com/plotly/plotly.js/issues/4780) to show you’re interested in this feature?]

From what I know, Dash Enterprise is usually purchased for these reasons:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/0/2/02af71a1aefc9fbcc5fcd9b647b803d4b59334a7.png)

---

<div class="post-metadata">

**Author:** ![matan3](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@matan3](https://community.plotly.com/u/matan3)\
**Post date:** [June 26, 2024, 11:13am UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/15 "2024-06-26T11:13:46Z")

</div>

Thanks for the licensing comments! the feature request must be no more important than any other dozens of floating feature requests of course. It’s probably a little like the hover texts in bar charts I guess.

---

<div class="post-metadata">

**Author:** ![Saratoga](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/saratoga/32/28634_2.png) [@Saratoga](https://community.plotly.com/u/Saratoga)\
**Post date:** [June 29, 2024, 4:53pm UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/16 "2024-06-29T16:53:08Z")

</div>

Now that I’m working on my drawing bar I had to modify the Plotly file to be able to manipulate the shapes more. I’ll share the code I added while an update comes out that includes these changes. Basically the only thing I did was add listeners to the shapes and emit a plotly event

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/9/8/985c09d139d3162a12b403982ad2e36ed0036637.png)

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/6/7/679965cbcbfc2338d22f29c4879f78c16cf0b649.png)

---

<div class="post-metadata">

**Author:** ![matan3](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@matan3](https://community.plotly.com/u/matan3)\
**Post date:** [July 9, 2024, 3:49pm UTC](https://community.plotly.com/t/show-name-of-shape-on-hover-or-always-visible/67353/18 "2024-07-09T15:49:38Z")

</div>

Is there a pull request for it?
