Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

3D Surface Streaming in Plotly

I am trying to generate a 3D surface using Plotly’s streaming API and I receive no errors in the actual Python code however I get the “Oops! An error occured while loading this plot’s data” on Plotly. Here is my code:

import plotly.plotly as py
import plotly.tools as tls
import plotly.graph_objs as go
from random import uniform
import pandas as pd
import time

tls.set_credentials_file(username='sterlingbutters', api_key='2dc5zzdbva')

stream_id = tls.get_credentials_file()['stream_ids']
token = stream_id[-1]

stream_id = dict(token=token)

z = []

surface = go.Surface(z=z, stream=stream_id)
data = [surface]
layout = go.Layout(
     title='Test',
     autosize=False,
     width=500,
     height=500,
     margin=dict(
         l=65,
         r=50,
         b=65,
         t=90
     )
 )
fig = go.Figure(data=data, layout=layout)
plot_url = py.iplot(fig, filename='elevations-3d-surface', auto_open=True)

s = py.Stream(stream_id=token)
s.open()

matrices = []
for p in range(5):
    matrix = []
    for x in range(25):
        row = []
        for y in range(25):
            row.append(uniform(25, 100))
        matrix.append(row)
    test = pd.DataFrame(matrix)
    print(test)
    matrices.append(matrix)
print(pd.DataFrame(matrices[1]))

i = 0
while True:
    step = 3
    z = matrices[i]
    s.write(go.Surface(z=z))
    time.sleep(step)
    i += 1
    if i == len(matrices):
        i = 0
    print(i)
    # print(pd.DataFrame(z))
s.close()

Did you ever find a resolution to this? I have been getting the same message today with two sets of code that were working fine just 30 minutes ago. Suspect its a server issue?

Thanks!
Craig

Hmmm, in your case if they were actually working and you were able to visualize your result then I suspect a server issue. For mine, if I remember correctly, no results were actually being generated for plotting and I had to reevaluate my code. You might run through your code just to make sure everything is how you left it when it was working.

I just went back through my code and inadvertently had switched to a max and min contour value that couldn’t be plotted. User code error! Shame Plotly doesn’t have a little more info in the error message.

Thanks for the response!