好的,所以我想更进一步。我不知道是否有可能用破折号。我想创建一个表单(可能是Flask的WTForm)。表格应该有date
和annotation/comments
部分。当有人提交表单时,它将保存到数据库中。然后破折号将读取它并显示在图表上。我的图看起来像这样:在x-axis
上将是来自FlaskForm的date
,它代表事件存储在数据库中,当我悬停到那个确切的annotation
时,date
将在图表中显示:类似于这个:
现在,请你告诉我是否可能?我应该使用哪些工具?这只是一个概念,但我认为对每个人都有帮助。
在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
希望这能回答你的问题。另请参阅散点图中的mode='lines+markers+text'
(plotly doc的Adding Text to Data in Line and Scatter Plots
部分)