Skip to content

Instantly share code, notes, and snippets.

@TristanAmond
Created July 17, 2016 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TristanAmond/c18d1d70ce54bc5a3dd0d840185cd07f to your computer and use it in GitHub Desktop.
Save TristanAmond/c18d1d70ce54bc5a3dd0d840185cd07f to your computer and use it in GitHub Desktop.
# initialize plotly credentials
plotly_tools.set_credentials_file(username='t_amond', api_key='REDACTED')
def update_plotly(self, url):
fileoption = 'extend'
time = datetime.datetime.now()
h,t = dht.read_retry(dht.DHT22, 4)
t = 9.0/5.0 * t + 32
t_str = "%.2f" % t
h_str = "%.2f" % h
# Temperature graph
trace1 = Scatter(
x= time,
y= t_str,
mode='lines+markers',
name='Temperature',
#This makes the line path curvy (spline-y)
line=dict(
shape='spline'
)
)
# Humidity graph
trace2 = Scatter(
x= time,
y= h_str,
mode='lines+markers',
name='Humidity',
line=dict(
shape='spline'
)
)
data = Data([trace1, trace2])
#set layout
layout = Layout(title="Terrarium Humidity & Temperature over Time")
#initialize graph figure
fig = Figure(data=data, layout=layout)
#generate URL to graph webpage
graph_url = plotly_master.plot(fig, filename='carnplantmonitor', fileopt='extend', auto_open=False)
url = graph_url
print("Plot.ly updated successfully.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment