完全自定义悬停框:Python以适合文本 [英] Customize Hover Box Plotly: Python to Fit Text

查看:52
本文介绍了完全自定义悬停框:Python以适合文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以自定义鼠标悬停文本框?我必须在悬停框中显示的文本很长,无法显示在屏幕上.有没有一种方法可以更改悬停文本框的尺寸或使文本变小以使其全部适合屏幕.更好的是,在图表的侧面有一个固定的框,当我在该数据点上滚动时会显示相应的注释,但是我不确定该怎么做.

Is there a way to customize the hover text box in plotly? The text I have to show up in the hover box is quite long and does not fit on the screen. Is there are a way to change the dimensions of the hover text box or make the text smaller to have it all fit on the screen. Even better would be a fixed box on the side of the chart that shows the corresponding note as I scroll over that data point but I am not sure how to do that.

这里是我要处理的一些相似长度文本的示例.

Here is a sample of what I'm trying to do with some similar length text.

import plotly.plotly as py
from plotly.graph_objs import *
import plotly
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd


notes=["Clinton is also navigating delicate ties with Israel and the American Jewish community, an influential group of voters and donors. Israeli Prime Minister Benjamin Netanyahu, a fierce critic of the Obama administration's outreach to Iran, described the framework deal as a threat to the very survival of his nation.", "Fire crews in Cambria County were called to the Revloc duplex Friday morning and found much of the building engulfed in flames. Chief Deputy Coroner Jeffrey Leeds said at least seven people were in the duplex and all, but one, were able to get out safely.Witnesses said Jake Lewis, 24, re-entered the house to rescue 65-year-old Anna LaJudice. But father, Robert LaJudice, told The (Altoona) Mirror.Their bodies were later recovered. The deputy coroner said autopsies determined that both died from smoke and gas inhalation.", "As crews worked to tear down the rest of the home, Ott said she planned to attend a church service and say a prayer for the family."]
balance=[1000,2000,4000]
dates=[1,2,3]


data1 = Data([
    Scatter(
        x=dates,
        y=balance,
        mode='markers',
        text=notes,        
    )
])
layout = Layout(
    title='Hover over the points to see the text',autosize=True,   
)
fig = Figure(data=data1, layout=layout,)

fig['layout'].update(
    hovermode='closest',  
    showlegend=False,     
    autosize=True,       

)
plot_url = py.plot(fig, filename='hover-chart-basic')
py.plot(fig, filename='hover-chart-basic')

任何帮助将不胜感激!

推荐答案

您可能需要查看注释以创建固定的文本框.在此处查看我们的文档: https://plot.ly/python/text-and-annotations/您将看到如何为注释或悬停文本指定字体大小.

You may want to look into annotations to create a fixed text box. Check out our documentation here: https://plot.ly/python/text-and-annotations/ You'll see how to specify font sizes for either annotations or hover text.

这篇关于完全自定义悬停框:Python以适合文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆