Black Lives Matter. Please consider donating to Black Girls Code today.
https://www.blackgirlscode.com

Streaming not working anymore

Hi for several years I was using plotly with online streaming feature.
Without any change of code it stopped to work because RPi was outdated (SSL).
Then I loaded new raspbian and plotly from python-plotly debian package.

What I can see now are several warnings about deprecated calls.

/usr/lib/python2.7/dist-packages/plotly/graph_objs/_deprecations.py:504: DeprecationWarning:

plotly.graph_objs.Stream is deprecated.
Please replace it with one of the following more specific types

  • plotly.graph_objs.scatter.Stream
  • plotly.graph_objs.area.Stream

/usr/lib/python2.7/dist-packages/plotly/graph_objs/_deprecations.py:372: DeprecationWarning:

plotly.graph_objs.Line is deprecated.
Please replace it with one of the following more specific types

  • plotly.graph_objs.scatter.Line
  • plotly.graph_objs.layout.shape.Line
  • etc.

/usr/lib/python2.7/dist-packages/plotly/graph_objs/_deprecations.py:531: DeprecationWarning:

plotly.graph_objs.XAxis is deprecated.
Please replace it with one of the following more specific types

  • plotly.graph_objs.layout.XAxis
  • plotly.graph_objs.layout.scene.XAxis

/usr/lib/python2.7/dist-packages/plotly/graph_objs/_deprecations.py:558: DeprecationWarning:

plotly.graph_objs.YAxis is deprecated.
Please replace it with one of the following more specific types

  • plotly.graph_objs.layout.YAxis
  • plotly.graph_objs.layout.scene.YAxis

/usr/lib/python2.7/dist-packages/plotly/graph_objs/_deprecations.py:39: DeprecationWarning:

plotly.graph_objs.Data is deprecated.
Please replace it with a list or tuple of instances of the following types

  • plotly.graph_objs.Scatter
  • plotly.graph_objs.Bar
  • plotly.graph_objs.Area
  • plotly.graph_objs.Histogram
  • etc.

I tried to resolve these warnings and also used the latest streaming examples, but the problem is same.

Code hangs here:

py.plot(fig, filename='My Plot')

after calling it is sitting there for unlimited time with unknown reason.
I dont know how to debug it or find why it is happening.

I tried also py.iplot() with the same result.

Can you help me please? How to make it work again. I am using Python 2.7.

Here is my source code:

import plotly.plotly as py
from plotly.graph_objs import Scatter, Layout, Figure, Data, Stream, XAxis, YAxis, Legend, Line

while True:
    if plotly_running == 0:
        break
    else:
        time.sleep(1)
        print "Waiting for plotly thread to end.."

with open('./config.json') as config_file:
    plotly_user_config = json.load(config_file)
    
trace_a = Scatter(
    x=[],
    y=[],
    stream=Stream(
        token=plotly_user_config['plotly_streaming_tokens'][0],
        maxpoints=1000
    ),
    yaxis='y',
    name='A',
    line=Line(
        color="blue"
    ),
)

trace_b = Scatter(
    x=[],
    y=[],
    stream=Stream(
        token=plotly_user_config['plotly_streaming_tokens'][1],
        maxpoints=1000
    ),
    xaxis='x2',
    yaxis='y2',
    name='B',
    line=Line(
        color="rgb(212, 189, 74)"
    ),
)

trace_e = Scatter(
    x=[],
    y=[],
    stream=Stream(
        token=plotly_user_config['plotly_streaming_tokens'][4],
        maxpoints=1000
    ),
    yaxis='y',
    name='C',
    line=Line(
        color="green"
    ),
)
    
trace_c = Scatter(
    x=[],
    y=[],
    stream=Stream(
        token=plotly_user_config['plotly_streaming_tokens'][3],
        maxpoints=1000
    ),
    yaxis='y',
    name='D',
    line=Line(
        color="red"
    ),
)

trace_d = Scatter(
    x=[],
    y=[],
    stream=Stream(
        token=plotly_user_config['plotly_streaming_tokens'][2],
        maxpoints=1000
    ),
    xaxis='x2',
    yaxis='y2',
    name='F',
    line=Line(
        color="orange"
    ),
)
    
trace_f = Scatter(
    x=[],
    y=[],
    stream=Stream(
        token=plotly_user_config['plotly_streaming_tokens'][5],
        maxpoints=500
    ),
    xaxis='x2',
    yaxis='y2',
    name='G',
    line=Line(
        color="purple"
    ),
)

layout = Layout(
    title='My Plot Data',
    showlegend=True,
    width=600,
    height=600,
    autosize=True,

    xaxis=XAxis(
        anchor='y'
    ),
    xaxis2=XAxis(
        anchor='y2'
    ),
    yaxis=YAxis(
        title='Temp [C]',
        domain=[0.6, 1]
    ),
    yaxis2=YAxis(
        title='Common',
        range=[0, 100.0],
        domain=[0, 0.4]
    )
)
    
data = Data([trace_a, trace_b, trace_c, trace_d, trace_e, trace_f])
fig = Figure(data=data, layout=layout)

py.sign_in(plotly_user_config["plotly_username"], plotly_user_config["plotly_api_key"])

print py.plot(fig, filename='My Plot')


stream_a = py.Stream(plotly_user_config['plotly_streaming_tokens'][0])
stream_a.open()

stream_b = py.Stream(plotly_user_config['plotly_streaming_tokens'][1])
stream_b.open()

stream_c = py.Stream(plotly_user_config['plotly_streaming_tokens'][4])
stream_c.open()

stream_d = py.Stream(plotly_user_config['plotly_streaming_tokens'][3])
stream_d.open()

stream_e = py.Stream(plotly_user_config['plotly_streaming_tokens'][2])
stream_e.open()

stream_f = py.Stream(plotly_user_config['plotly_streaming_tokens'][5])
stream_f.open()

while True:
    time.sleep(1)
    
    # write the data to plotly
    try:
        stream_a.write({'x': datetime.datetime.now(), 'y': "%.2f" % a})
        stream_b.write({'x': datetime.datetime.now(), 'y': "%.2f" % b})
        stream_d.write({'x': datetime.datetime.now(), 'y': "%.2f" % c})
        stream_e.write({'x': datetime.datetime.now(), 'y': "%.3f" % d})
        stream_c.write({'x': datetime.datetime.now(), 'y': "%.2f" % e})
        stream_f.write({'x': datetime.datetime.now(), 'y': "%.2f" % f})
    except Exception, e:
        print "> Plotly - " + str(e)

Hi there,

Unfortunately, Chart Studio Cloud no longer supports streaming features at all, although the Python code is still present for users of Chart Studio Enterprise, so there’s not a lot we can do to help you.