将表单添加到Dash / Plotly应用程序

问题描述 投票:6回答:1

好的,所以我想更进一步。我不知道是否有可能用破折号。我想创建一个表单(可能是Flask的WTForm)。表格应该有dateannotation/comments部分。当有人提交表单时,它将保存到数据库中。然后破折号将读取它并显示在图表上。我的图看起来像这样:enter image description herex-axis上将是来自FlaskForm的date,它代表事件存储在数据库中,当我悬停到那个确切的annotation时,date将在图表中显示:类似于这个:enter image description here

现在,请你告诉我是否可能?我应该使用哪些工具?这只是一个概念,但我认为对每个人都有帮助。

python plotly dashboard plotly-dash
1个回答
0
投票

在plotly中,您可以使用注释显示文本。例:

import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
    y=[0, 1, 3, 2, 4, 3, 4, 6, 5]
)

trace2 = go.Scatter(
    x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
    y=[0, 4, 5, 1, 2, 2, 3, 4, 2]
)

data = [trace1, trace2]

layout = go.Layout(
    showlegend=False,
    annotations=[
        dict(
            x=2,
            y=5,
            xref='x',
            yref='y',
            text='max',
            showarrow=True,
            arrowhead=7,
            ax=0,
            ay=-40
         )
    ]
)

fig = go.Figure(data=data, layout=layout)

iplot(fig)

参考:https://plot.ly/python/text-and-annotations

Plot with annotation

希望这能回答你的问题。另请参阅散点图中的mode='lines+markers+text'(plotly doc的Adding Text to Data in Line and Scatter Plots部分)

© www.soinside.com 2019 - 2024. All rights reserved.