Created
July 30, 2019 22:12
-
-
Save kperry2215/a98103f36e6850438f9722a32f6dd192 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def plot_data(df, x_variable, y_variable, title): | |
""" | |
Plot the x- and y- variables against each other, where the variables are columns in | |
a pandas dataframe | |
df: Pandas dataframe. | |
x_variable: String. Name of x-variable column | |
y_variable: String. Name of y-variable column | |
title: String. Desired title name | |
""" | |
fig, ax = plt.subplots() | |
ax.plot_date(df[x_variable], | |
df[y_variable], marker='', linestyle='-', label=y_variable) | |
fig.autofmt_xdate() | |
plt.title(title) | |
plt.show() | |
###Execute in main block | |
#Plot the data on a yearly basis, using 2019 as an example year | |
plot_data( | |
df=electricity_demand_df[(electricity_demand_df['Date_Time']>=pd.to_datetime('2019-01-01')) & | |
(electricity_demand_df['Date_Time']<pd.to_datetime('2020-01-01'))], | |
x_variable='Date_Time', | |
y_variable='Electricity_Demand_MWh', | |
title='TX Electricity Demand: 2019') | |
#Plot the data on a monthly basis, using January 2017 as an example | |
plot_data(df=electricity_demand_df[(electricity_demand_df['Date_Time']>=pd.to_datetime('2017-01-01')) & | |
(electricity_demand_df['Date_Time']<pd.to_datetime('2017-02-01'))], | |
x_variable='Date_Time', | |
y_variable='Electricity_Demand_MWh', | |
title='TX Electricity Demand: December 2017') | |
#Plot the data on a weekly basis, using July 1-7, 2019 as an example | |
plot_data(df=electricity_demand_df[(electricity_demand_df['Date_Time']>=pd.to_datetime('2019-07-01')) & | |
(electricity_demand_df['Date_Time']<pd.to_datetime('2019-07-07'))], | |
x_variable='Date_Time', | |
y_variable='Electricity_Demand_MWh', | |
title='TX Electricity Demand: December 2017') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment