繁体   English   中英

在 Plotly 悬停文本 (Python) 中更改字体大小并限制文本长度

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

我有一个由 9 个跟踪散点图组成的散点图,其中一个散点图将进入 Dash 仪表板。

我只提供了第一个跟踪以使代码更短更容易,但是如果您需要查看其他 8 个跟踪,我可以提供它们(它们都与此跟踪相似)。

我需要帮助来执行以下操作:

  1. 更改悬停文本的字体大小

  2. 给悬停文本一个截止长度,因为它继续离开页面。

     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' ) ) ) } ) ])

谢谢你们!

我没有运行您的完整示例,但是,就我而言,以下解决了该问题:

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

希望回答第 1 点。

编辑

刚刚找到这个页面,也可能有用https://plotly.com/python/hover-text-and-formatting/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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