Created
June 26, 2018 17:54
-
-
Save cudmore/13fff7867d70d07afa1d2ee8bbb72656 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
import pandas as pd | |
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot | |
import plotly.graph_objs as go | |
# initialize plotly to plot inside of Jupyter notebook | |
init_notebook_mode(connected=True) | |
# load the fridge.log into a pandas dataframe | |
filePath = 'fridge.log' | |
df = pd.read_csv(filePath) | |
# extact columns (these are not raw numbers yet) | |
mySeconds = df[['Seconds']] | |
myTemperature = df[['Temperature']] | |
myHumidity = df[['Humidity']] | |
# get the actual numbers from each column | |
mySeconds2 = mySeconds.iloc[:]['Seconds'] | |
myTemperature2 = myTemperature.iloc[:]['Temperature'] | |
myHumidity2 = myHumidity.iloc[:]['Humidity'] | |
# set up two traces to plot in plotly | |
trace1 = go.Scatter( | |
x=mySeconds2, | |
y=myTemperature2, | |
name='Temperature' | |
) | |
trace2 = go.Scatter( | |
x=mySeconds2, | |
y=myHumidity2, | |
name='Humidity', | |
yaxis='y2' | |
) | |
data = [trace1, trace2] | |
# make a plotly layout | |
layout = go.Layout( | |
title='Temperature And Humidity', | |
yaxis=dict( | |
title='Temperature (deg celcius)', | |
titlefont=dict( | |
# this is same as default plot color #1 | |
color='#1f77b4' | |
), | |
tickfont=dict( | |
# this is same as default plot color #1 | |
color='#1f77b4' | |
) | |
), | |
yaxis2=dict( | |
title='Humidity (%)', | |
#titlefont=dict( | |
# color='rgb(148, 103, 189)' | |
#), | |
#tickfont=dict( | |
# color='rgb(148, 103, 189)' | |
#), | |
titlefont=dict( | |
# this is same as default plot color #2 | |
color='#ff7f0e' | |
), | |
tickfont=dict( | |
# this is same as default plot color #2 | |
color='#ff7f0e' | |
), | |
overlaying='y', | |
side='right' | |
) | |
) | |
# plot with plotly | |
fig = go.Figure(data=data, layout=layout) | |
plot_url = iplot(fig, filename='multiple-axes-double') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment