Created
July 17, 2016 15:00
-
-
Save TristanAmond/c18d1d70ce54bc5a3dd0d840185cd07f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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