【问题标题】:What are Streaming API tokens in plotly?plotly 中的 Streaming API 令牌是什么?
【发布时间】:2019-04-01 17:37:23
【问题描述】:

最近,我一直在使用 plotly 进行数据可视化。我已经创建了一个情节,我需要制作一个新情节。我创建了 2 个 Streaming API 令牌并将它们添加到凭证文件中。我不知道这些流式令牌实际上做了什么。我可以使用不同的流式传输令牌来流式传输不同的情节吗?如果可以,请解释一下如何?我可以在多个跟踪上使用相同的流令牌吗?另外,我想知道在 plotly 中流式传输令牌的目的。

在 python 中进行流式传输:https://plot.ly/python/streaming-tutorial/

最初,我使用一个流式 API 令牌创建了一个绘图。现在,我想创建另一个单独的情节。我需要确保新情节不会覆盖第一个情节,为此我认为可以使用流式令牌,尽管不完全确定。

【问题讨论】:

  • 我不确定我是否明白你在问什么。您在此处链接的 plot.ly 页面指出 You will need one unique stream token for every trace object you wish to stream to. Thus if you have two traces that you want to plot and stream, you're going to require two unique stream tokens 而您的问题似乎正是在问这个问题。
  • Stream_ID 是您将数据连接到的(流)令牌。正如@ChrisLarson 所述。一个来源需要一个令牌,并且无法通过一个令牌流式传输两个来源。

标签: python api token plotly data-visualization


【解决方案1】:

只是为了向您展示here 提供的工作流程。它要求您在 Plotly 用户配置文件中设置两个不同的流。

stream_ids = tls.get_credentials_file()['stream_ids']

# Get stream id from stream id list 
stream_id_1 = stream_ids[0]
stream_id_2 = stream_ids[1]


# Make instance of stream id object 
stream_1 = go.Stream(
    token=stream_id_1,  # link stream id to 'token' key
    maxpoints=80      # keep a max of 80 pts on screen
)

stream_2 = go.Stream(
    token=stream_id_2,  # link stream id to 'token' key
    maxpoints=80      # keep a max of 80 pts on screen
)

# Initialize trace of streaming plot by embedding the unique stream_id
trace1 = go.Scatter(
    x=[],
    y=[],
    mode='lines+markers',
    stream=stream_1         # (!) embed stream id, 1 per trace

trace2 = go.Scatter(
    x=[],
    y=[],
    mode='lines+markers',
    stream=stream_2         # (!) embed stream id, 1 per trace
)

这应该为您完成工作。如前所述,有必要为您要显示的每个附加图使用附加流。

【讨论】:

  • 这解决了您的问题吗? @Kartikeya Sharma 那么请接受我的回答。 :)
猜你喜欢
  • 2013-07-21
  • 2011-11-23
  • 1970-01-01
  • 2017-11-11
  • 1970-01-01
  • 2016-10-06
  • 2018-02-02
  • 2018-04-17
  • 2021-09-01
相关资源
最近更新 更多