# Hover textbox dimensions

**URL:** <https://community.plotly.com/t/hover-textbox-dimensions/78914>\
**Category:** 📊 Plotly Python\
**Tags:** question\
**Created:** [September 30, 2023, 1:52pm UTC](https://community.plotly.com/t/hover-textbox-dimensions/78914 "2023-09-30T13:52:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tryharder](https://avatars.discourse-cdn.com/v4/letter/t/ba8739/32.png) [@tryharder](https://community.plotly.com/u/tryharder)\
**Post date:** [September 30, 2023, 1:52pm UTC](https://community.plotly.com/t/hover-textbox-dimensions/78914/1 "2023-09-30T13:52:06Z")

</div>

Hello,

I am generating a scatter plot with hover text on each point and the box always has only one line, meaning it is thin and long. I am trying to control the dimensions of the hover box so that it has a fixed horizontal width and its height changes to accommodate the text, but with no success. Based on the documentation, I passed a hoverlabel={‘width’:100}/{‘namelength’:100} but it did not have an effect on the result.

Below is the code block that generates the points. Any suggestions?

` fig.add_trace( go.Scattergl( x=selection.x, y=selection.y, hovertext= selection.doc, hoverinfo="text", text=selection.text, mode='markers+text', name=name, textfont=dict( size=12, ), marker=dict(size=5, opacity=0.5) ) )`

---

<div class="post-metadata">

**Author:** ![farispriadi](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/farispriadi/32/26759_2.png) [@farispriadi](https://community.plotly.com/u/farispriadi)\
**Post date:** [October 8, 2023, 12:23am UTC](https://community.plotly.com/t/hover-textbox-dimensions/78914/2 "2023-10-08T00:23:08Z")

</div>

Hi @tryharder,

You can try to wrap the hovertext explicitly by creating custom function that return `wrapped_hovertext` series.

To do this you will need to import `textwrap` module.  
The `textwrap` module in Python is an in-built module, so you don’t have to install any additional module.

Set how long the width of every line, by assigning integer value to `width` argument. I set at most 20 character long as default.

Then call this function and assign return value on `hovertext` keyword argument.

My suggestion based on your code will be

```auto
import textwrap

# wrap hovertext function, a line has at most width characters long.
def wrap_hovertext(hovertext, width=20):
    wrapped_hovertext = ["<br>".join(textwrap.wrap(text,width=width)) for text in hovertext]
    return wrapped_hovertext     

fig.add_trace( go.Scattergl( x=selection.x, y=selection.y, hovertext= wrap_hovertext(selection.doc), 
hoverinfo="text", text=selection.text, mode='markers+text', name=name, textfont=dict( size=12, ), 
marker=dict(size=5, opacity=0.5) ) )

```

Hope this help.
