# Customize Y-axis title length

**URL:** <https://community.plotly.com/t/customize-y-axis-title-length/62115>\
**Category:** 📊 Plotly Python\
**Tags:** question\
**Created:** [March 21, 2022, 10:14am UTC](https://community.plotly.com/t/customize-y-axis-title-length/62115 "2022-03-21T10:14:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![saurabh31](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@saurabh31](https://community.plotly.com/u/saurabh31)\
**Post date:** [March 21, 2022, 10:14am UTC](https://community.plotly.com/t/customize-y-axis-title-length/62115/1 "2022-03-21T10:14:32Z")

</div>

Hello Guys,  
I’m wondering whether we can add a tooltip for Y-axis title to show complete text only when hover in Subplot?  
For Example, I have Subplot with three rows and one column and I want to show large length of text for each subplot vertically but doing that text is colliding with each other.

 ![subplotExample](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/f/3/f3749f67f56e4580cee3dd6110073121301ac2fe.png)  
As You can see in this image, Vertical text are getting mixed with each other.

---

<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:** [March 21, 2022, 9:59pm UTC](https://community.plotly.com/t/customize-y-axis-title-length/62115/2 "2022-03-21T21:59:19Z")

</div>

Hey @saurabh31, welcome to community.  
I couldn’t see anything about axes title tooltip. So I created a custom approach.

```auto
import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = make_subplots(rows=3, cols=1)

#Trace1
fig.append_trace(go.Scatter(
    x=[3.5, 4.5],
    y=[1.75, 2.75],
    mode='markers'),row=1, col=1)

#Trace1 Fake Y Axis
fig.add_trace(go.Scatter(
    x=[0,0,0.01,0.01,0],
    y=[0,3.5,3.5,0,0],
    fill="toself",
    mode='lines',
    fillcolor='black',
    line=dict(color="black",width=0.1),
    text='My Custom Text 11111111111111',
    opacity=1), row=1, col=1)

#Trace2
fig.append_trace(go.Scatter(
    x=[1.5, 4.5],
    y=[0.75, 0.75],
    mode='markers'),row=2, col=1)

#Trace2 Fake Y Axis
fig.add_trace(go.Scatter(
    x=[0,0,0.01,0.01,0],
    y=[0,3.5,3.5,0,0],
    fill="toself",
    mode='lines',
    fillcolor='black',
    line=dict(color="black",width=0.1),
    text='My Custom Text 22222222222222',
    opacity=1), row=2, col=1)

#Trace3
fig.append_trace(go.Scatter(
    x=[1.5, 4.5],
    y=[0.75, 3.75],
    mode='markers'),row=3, col=1)

#Trace3 Fake Y Axis
fig.add_trace(go.Scatter(
    x=[0,0,0.01,0.01,0],
    y=[0,3.5,3.5,0,0],
    fill="toself",
    mode='lines',
    fillcolor='black',
    line=dict(color="black",width=0.1),
    text='My Custom Text 33333333333333',
    opacity=0), row=3, col=1) # You can make it invisible (opacity=0). Hover on still shows text.
    
   
fig.update_xaxes(range=[0, 7], showgrid=True)
fig.update_yaxes(range=[0, 3.5])

fig.show()

```

 ![hover1](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/5/8/585de5785ba792ff9aa6511706a327d22f0172fd.png)

Hope that helps.

Have a nice day.

---

<div class="post-metadata">

**Author:** ![saurabh31](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@saurabh31](https://community.plotly.com/u/saurabh31)\
**Post date:** [March 22, 2022, 5:13am UTC](https://community.plotly.com/t/customize-y-axis-title-length/62115/3 "2022-03-22T05:13:27Z")

</div>

Hey @akroma,  
Thank you for response. Solution is very good, but I cannot add another trace in my graphs. What I want is hide and show title as I hover over title or show full text when I click on title, something like ellipsis with ‘…’ as a button.  
Thank You.

---

<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:** [March 22, 2022, 9:04pm UTC](https://community.plotly.com/t/customize-y-axis-title-length/62115/4 "2022-03-22T21:04:28Z")

</div>

Maybe something like this ? 😃

![title_](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/6/3/632560e4245e9f0c3af5fda54c57e2ed64bae971.gif)

---

<div class="post-metadata">

**Author:** ![saurabh31](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@saurabh31](https://community.plotly.com/u/saurabh31)\
**Post date:** [March 23, 2022, 12:15pm UTC](https://community.plotly.com/t/customize-y-axis-title-length/62115/5 "2022-03-23T12:15:54Z")

</div>

@akroma Yes, Something like this. How did you do it?

---

<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:** [March 23, 2022, 12:31pm UTC](https://community.plotly.com/t/customize-y-axis-title-length/62115/6 "2022-03-23T12:31:33Z")

</div>

> [@saurabh31](#):
>
> something like ellipsis with ‘…’ as a button.

Actually you gave me the idea : )

I created a button and used callback function to change the title but you have to tweak some css properties.

```auto
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

fig = make_subplots(rows=3, cols=1)

#Trace1
fig.append_trace(go.Scatter(
    x=[3.5, 4.5],
    y=[1.75, 2.75],
    mode='markers'),row=1, col=1)

#Trace2
fig.append_trace(go.Scatter(
    x=[1.5, 4.5],
    y=[0.75, 0.75],
    mode='markers'),row=2, col=1)

#Trace3
fig.append_trace(go.Scatter(
    x=[1.5, 4.5],
    y=[0.75, 3.75],
    mode='markers'),row=3, col=1)

    
fig.update_layout(width=800, height=800, margin=dict(l=0, r=0, t=0, b=0))
fig.update_xaxes(range=[0, 7], showgrid=True)
fig.update_yaxes(range=[0, 3.5])

#Button CSS properties 
my_style={"height": "25px",
          "width":"155px",
          "margin-top": "180px",
          "margin-left": "0px",
          "transform": "rotate(-90deg)",
          "background-color":"white", #hide button
          "border":"none" #hide button
          }

app = dash.Dash( __name__ )

app.layout = html.Div([

    #BUTTON
    html.Div([
        html.Button('Y Axis ...', id='y_axis_1', n_clicks=0, style=my_style)
        ]),
    
    #GRAPH
    html.Div([dcc.Graph(figure=fig,id="my_figure")],
             style={'margin-left':'100px','margin-top':'-100px',}
             )  
])

@app.callback(Output('y_axis_1', 'children'),
              Input('y_axis_1', 'n_clicks')
              )

def change_button_style(n_clicks):

    if n_clicks%2 == 0:

        return "Short Title ..."

    else:

        return "Y-axis Long Title"

if __name__ == " __main__":
    app.run_server(debug=True)

```

---

<div class="post-metadata">

**Author:** ![saurabh31](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@saurabh31](https://community.plotly.com/u/saurabh31)\
**Post date:** [March 24, 2022, 5:54am UTC](https://community.plotly.com/t/customize-y-axis-title-length/62115/7 "2022-03-24T05:54:39Z")

</div>

Hey @akroma, awesome finding. Thank you.
