簡體   English   中英

自定義懸停框繪圖:Python 以適應文本

[英]Customize Hover Box Plotly: Python to Fit Text

有沒有辦法在 plotly 中自定義懸停文本框? 我必須在懸停框中顯示的文本很長,無法顯示在屏幕上。 有沒有辦法改變懸停文本框的尺寸或縮小文本以使其適合屏幕。 更好的是圖表側面的固定框,當我滾動該數據點時顯示相應的注釋,但我不知道如何做到這一點。

這是我嘗試對一些相似長度的文本執行的操作的示例。

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/您將看到如何為注釋或懸停文本指定字體大小。

秘訣是在您的懸停字符串文本中每大約 90 個字符插入一個 html <br> 標簽。 您可以使用下面的正則表達式來匹配每約 90 行。

(.{1,90})(\\s|$)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM