{
"metadata": {
"name": "",
"signature": "sha256:b911abd0316db8c88af3dae5b51ff675d0e6aabab5b9306192816597779d063f"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Plotly Streaming"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import plotly.plotly as py\n",
"from plotly.graph_objs import *"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import time\n",
"import datetime\n",
"import numpy as np"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import plotly.tools as tls\n",
"stream_ids = tls.get_credentials_file()['stream_ids']\n",
"stream_ids"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 3,
"text": [
"[u'p17pxe0idb', u'ilzladc8ro', u'o72o1p08y4', u'81dygs4lct']"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def Plotter(): # defines layout and traces for plot\n",
" layout = Layout(\n",
" title='Bobs environment',\n",
" yaxis=YAxis(\n",
" domain=[0, 0.5]\n",
" ),\n",
" yaxis2=YAxis(\n",
" domain=[0.5, 1]\n",
" )\n",
" )\n",
" trace1 = Scatter(\n",
" x=[],\n",
" y=[],\n",
" name='Room Temp *C',\n",
" stream=dict(\n",
" token=stream_ids[0],\n",
" maxpoints=1000\n",
" )\n",
" )\n",
" trace2 = Scatter(\n",
" x=[],\n",
" y=[],\n",
" name = 'Atmospheric pressure mB',\n",
" yaxis = 'y2',\n",
" stream=dict(\n",
" token=stream_ids[1],\n",
" maxpoints=1000\n",
" )\n",
" )\n",
" trace3 = Scatter(\n",
" x=[],\n",
" y=[],\n",
" name = 'Outside Temp *C',\n",
" stream=dict(\n",
" token=stream_ids[2],\n",
" maxpoints=1000\n",
" )\n",
" )\n",
" trace4 = Scatter(\n",
" x=[],\n",
" y=[],\n",
" name = 'Light Level',\n",
" yaxis = 'y2',\n",
" stream=dict(\n",
" token=stream_ids[3],\n",
" maxpoints=1000\n",
" )\n",
" )\n",
" data = Data([trace1, trace2, trace3, trace4])\n",
" fig = Figure(data=data, layout=layout)\n",
" unique_url = py.plot(fig, filename='RoomF (HemiBob)')\n",
" #my_data = Data([trace1, trace2, trace3, trace4])\n",
" #unique_url = py.plot(my_data, layout, filename='RoomF',auto_open=False,fileopt='extend')\n",
" s = py.Stream(stream_ids[0])\n",
" q = py.Stream(stream_ids[1])\n",
" u = py.Stream(stream_ids[2])\n",
" r = py.Stream(stream_ids[3])\n",
" return s,q,u,r"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"N = 100 # number of data points to stream\n",
"\n",
"def dummy_data(n):\n",
" return (np.random.random(N) for i in range(n))\n",
"\n",
"# Use some dummy data\n",
"data_s, data_q, data_u, data_r = dummy_data(4)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"s,q,u,r = Plotter() # get the data streams then open them to plot.ly\n",
"s.open()\n",
"q.open()\n",
"u.open()\n",
"r.open()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"i = 0\n",
"\n",
"while i\n",
" \n",
"\n",
"\n",
"Got Questions or Feedback?
\n",
"\n",
"About Plotly\n",
"\n",
"* email: feedback@plot.ly \n",
"* tweet: \n",
"@plotlygraphs\n",
"\n",
"Notebook styling ideas
\n",
"\n",
"Big thanks to\n",
"\n",
"* Cam Davidson-Pilon\n",
"* Lorena A. Barba\n",
"\n",
"
"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# CSS styling within IPython notebook\n",
"from IPython.core.display import HTML\n",
"import urllib2\n",
"def css_styling():\n",
" url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css'\n",
" styles = urllib2.urlopen(url).read()\n",
" return HTML(styles)\n",
"\n",
"css_styling()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n",
"\n"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"text": [
""
]
}
],
"prompt_number": 8
}
],
"metadata": {}
}
]
}