简体   繁体   中英

Change font size and restrict text length in Plotly hover text (Python)

I have a plotly scatter plot consisting of 9 trace scatter plots on one that is going into a Dash Dashboard.

I have only provided the first trace to make the code shorter and easier but If you need to see the other 8 I can provide them (they are all similar to this trace).

I need help to do the following:

  1. Change the font-size of the hover text

  2. Give a cut-off length to the hover text as at the moment it continues off the page.

     trace0= go.Scatter( x =df[df['Topic'] == 'Time consuming tasks']['x'], y = df[df['Topic'] == 'Time consuming tasks']['y'], mode = 'markers', text= df[df['Topic'] == 'Time consuming tasks']['challenges'], marker = dict( size = 9, line = dict( width = 2, ) ), name = 'First Plot', showlegend=True) app.layout = html.Div([dcc.Graph(id='scatterplot', figure = {'data' : [trace0, trace1, trace2, trace3, trace4, trace5, trace6, trace7, trace8], 'layout' : go.Layout(title='Biggest hindrances in your life?', xaxis = {'title':'x axis'}, yaxis = {'title': 'y axis'}, height = 550, titlefont= {'size':33}, hovermode = 'closest', legend=dict( traceorder='normal', font=dict( family='sans-serif', size=25, color='#000' ) ) ) } ) ])

Thanks guys!

I did not run your full example, however, in my case, the following solved the issue:

go.Layout(title='Biggest hindrances in your life?',
          #other options for the plot
           hoverlabel=dict(font=dict(family='sans-serif', size=25)))

Hope that answeres point 1.

Edit

Just found this page, might also be useful https://plotly.com/python/hover-text-and-formatting/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM