Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 4e2768b

Browse files
committed
Update the Plotly interface to the 1.0 syntax
1 parent db39bdf commit 4e2768b

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

README.md

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Example config.json:
3030

3131
Create your sensor reading script, and start importing some modules in it!
3232
```python
33-
import plotly # plotly library
33+
import plotly.plotly as py # plotly library
34+
from plotly.graph_objs import Scatter, Layout # plotly graph objects
3435
import json # used to parse config.json
3536
import time # timer functions
3637
import readadc # helper functions to read ADC from the Raspberry Pi
@@ -49,23 +50,15 @@ stream_token = plotly_user_config['plotly_streaming_tokens'][0]
4950

5051
Initialize a Plotly Object
5152
```python
52-
p = plotly.plotly(username, api_key)
53+
py.sign_in(username, api_key)
5354
```
5455

5556

5657
Initialize your graph (not streaming yet)
5758
```python
58-
p.plot([
59-
{'x': [],
60-
'y': [],
61-
'type': 'scatter',
62-
'stream': {
63-
'token': stream_token,
64-
'maxpoints': 1000
65-
}
66-
}],
67-
filename='Raspi Graph',
68-
fileopt='overwrite')
59+
data = [Scatter(x=[],y=[],stream={'token': stream_token, 'maxpoints': 1000})]
60+
layout = Layout(title='Live graphing from a Raspberry Pi')
61+
py.plot(Figure(data=data, layout=layout), filename='Raspi Graph', auto_open=False)
6962
```
7063

7164
Specify the connected channel for your sensor
@@ -80,16 +73,14 @@ readadc.initialize()
8073

8174
Initialize the Plotly Streaming Object
8275
```python
83-
stream = plotly.Stream(stream_token)
84-
i = 0
76+
stream = py.Stream(stream_token)
77+
stream.open()
8578
```
8679

8780
Start looping and streamin'!
8881
```python
89-
stream.open()
9082
while True:
9183
sensor_data = readadc.readadc(sensor_pin, readadc.PINS.SPICLK, readadc.PINS.SPIMOSI, readadc.PINS.SPIMISO, readadc.PINS.SPICS)
92-
stream.write({'x': datetime.datetime.now(), 'y': sensor_data })
93-
i+=1 # increment 1 on the 'x' axis with each reading
84+
stream.write({'x': datetime.datetime.now(), 'y': sensor_data})
9485
time.sleep(0.1) # delay between stream posts
9586
```

0 commit comments

Comments
 (0)