Last active
July 25, 2017 14:44
-
-
Save arunreddy/c2cc699a37a12fbf69415f4561475605 to your computer and use it in GitHub Desktop.
multiple.py
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 matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
from matplotlib.dates import DateFormatter | |
from datetime import timedelta, date | |
def datetime(x): | |
return np.array(x, dtype = np.datetime64) | |
if __name__ == '__main__': | |
# Save the file as a .csv file from your excel. | |
file_name = 'RTC_RTD_DNI_LBMP_EXT.csv' | |
# Read the file into the code. | |
df = pd.read_csv(file_name, parse_dates = ['BINDING_TIMESTAMP']) | |
# This is for xticks.. the format for ticks in the x-axis. Lets not use this for now. | |
date_formatter = '%H:%M' | |
xfmt = DateFormatter(date_formatter) | |
# loop through all the unique zone_names | |
for zone_name in df['ZONE_NAME'].unique(): | |
# Read all the data for the zone_name | |
print('> Reading all the data for the zone %s', zone_name) | |
dfz = df[df.ZONE_NAME == zone_name] | |
#Goes through dates. | |
for i in range(1, 32): | |
start = date(2016, 12, i) | |
end = start + timedelta(1) | |
mask = (dfz['BINDING_TIMESTAMP'] >= start) & (dfz['BINDING_TIMESTAMP'] < end) | |
_dfz = dfz[mask] | |
# fig = plt.figure() | |
# ax = plt.gca() | |
# _dfz = dfz | |
# GRAPH PLOTTING | |
# Dont change | |
# ----------------------------------------------------------------------------------------------------- | |
fig, ax = plt.subplots(figsize = (15, 5)) | |
fig.subplots_adjust(right = 0.75) | |
# Twin the x-axis twice to make independent y-axes. | |
axes = [ax, ax.twinx()] | |
# Move the last y-axis spine over to the right by 20% of the width of the axes | |
axes[1].spines['right'].set_position(('axes', 1.0)) | |
# To make the border of the right-most axis visible, we need to turn the frame | |
# on. This hides the other plots, however, so we need to turn its fill off. | |
axes[-1].set_frame_on(True) | |
axes[-1].patch.set_visible(False) | |
# ----------------------------------------------------------------------------------------------------- | |
# Set the title | |
plt.title("Zone %s" % (zone_name)) | |
# Graph 01 -- all the axes[0] variables refer to graph 1 | |
axes[0].plot(x = datetime(_dfz['BINDING_TIMESTAMP']), y = _dfz['RTD_ZONAL_LBMP'], label = 'RTD_LBMP', c = 'red') | |
axes[0].plot(x = datetime(_dfz['BINDING_TIMESTAMP']), y = _dfz['RTC_ZONAL_LBMP'], label = 'RTC_LBMP', c = 'blue') | |
axes[0].set_ylabel('Load Fixed MW') | |
# Graph 02 -- all the axes[1] variables refer to graph 2 | |
axes[1].plot(datetime(_dfz['BINDING_TIMESTAMP']), _dfz['RTC_RTD_div ($/MWh))'], label = 'RTC_RTD_div ($/MWh))', c = 'green') | |
axes[1].set_ylabel('RTC_RTD_div ($/MWh))') | |
# xaxis set up | |
axes[0].xaxis.set_major_locator(MinuteLocator(byminute = [0, 30], interval = 1)) | |
axes[0].xaxis.set_major_formatter(xfmt) | |
plt.xlabel('Binding Timestamp') | |
labels = axes[0].get_xticklabels() | |
plt.setp(labels, rotation = 90) | |
plt.grid(linestyle = 'dotted') | |
axes[0].legend(loc = 'upper left') | |
axes[1].legend(loc = 'upper right') | |
plt.tight_layout() | |
start = df['BINDING_TIMESTAMP'].min() | |
end = df['BINDING_TIMESTAMP'].max() | |
plt.xlim(start, end) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment