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

标签 python plotly dashboard plotly-dash

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

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

最佳答案

在 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'在散点图中(Adding Text to Data in Line and Scatter Plots 部分 plotly 文档)

关于python - 将表单添加到 Dash/Plotly 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51837333/

相关文章:

templates - 在不编辑默认模板的情况下在 Magento 后端添加自定义仪表板 "box"的正确方法是什么?

Python 计数单词

python - 如何卡住 datetime.now 以进行单元测试

python - 计算每行 pandas 的较高行数

python - 如何为每个ID分配一个组号(n=1,2,3.....)?

r - 如何将图例从颜色条更改为 "regular legend",仍然使用颜色渐变

python - 在 Dash 中实现一个控制台,该控制台会根据服务器上的中间步骤的状态进行更新

python - 与同一轴嵌套的热图 python dash

python - 如何在python中使用plotly方法添加标题和副标题

r - 如何在 rmarkdown 中使用 Twitter bootstrap 网格布局?