This program is meant to plot the correlation between two types of weather data (temperature, pressure, or humidity) obtained from a single sensor
In [ ]:
# Shoutout to my homies at StackOverFlow - you da real MVPs
import pandas as pd
import scipy.stats
from bokeh.plotting import figure
from bokeh.io import show
from bokeh.models import HoverTool , Label
In [ ]:
weather_file = input("Write the name of the weather file you want to use: ")
df = pd.read_csv(weather_file)
# Ravel converts the columns that have been read in to 1-d arrays
temp = df.as_matrix(columns=df.columns[3:4])
temp = temp.ravel()
humidity = df.as_matrix(columns=df.columns[4:5])
humidity = humidity.ravel()
pressure = df.as_matrix(columns=df.columns[5:])
pressure = pressure.ravel()
This program uses bokeh, so the resulting plot is an HTML file
In [ ]:
# User is asked which two variables to plot against each other
xaxis = input("X axis plots: temp, humidity, or pressure: ")
yaxis = input("Y axis plots: temp, humidity, or pressure: ")
# The plot is made, and the Pearson correlation coefficient is calculated and added to the plot
p = figure(tools = "pan,wheel_zoom,box_zoom,reset")
p.add_tools(HoverTool(tooltips=[("(x,y)", "($x, $y)")]))
correlation = Label(x=50, y=50, x_units='screen', y_units='screen', text="Pearson r and p: "+ str(scipy.stats.pearsonr(xaxis, yaxis)))
p.add_layout(correlation)
p.circle(x = xaxis, y = yaxis, color = "firebrick", size = 0.5)
show(p)