简体   繁体   中英

What are Streaming API tokens in plotly?

Recently, I have been working on data visualization using plotly. I have created a plot and I need to make a new plot. I have created 2 Streaming API tokens and added them to credentials file. I don't have any idea what these streaming tokens actually do. Can I use different streaming tokens to stream different plots, if yes please explain me how? Can I use same streaming token on multiple traces? Also, I would like to know the purpose of streaming tokens in plotly.

plotly streaming in python : https://plot.ly/python/streaming-tutorial/

Initially, I have created a plot with one streaming API token. Now, I want to create another separate plot. I need to be sure that new plot will not override first plot and for that I think streaming tokens can be used, although not completely sure.

Just to show you the work flow presented here . It requires you to setup the two different streams within your Plotly user profile.

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
)

This should do the work for you. As mentioned before, it is neccessary to use an additionall stream for each additional plot you want to show.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM