I am attempting to write my first python script using pandas. I have 10 years of wind data (1min readings) that i need to create monthly plots with the speed and direction plotted on each plot.
The input csv data looks like this:
Date,Speed,Dir,
2014-01-01 00:00:00, 13, 179,
2014-01-01 00:01:00, 13, 178,
2014-01-01 00:02:00, 11, 169,
2014-01-01 00:03:00, 11, 178,
2014-01-01 00:04:00, 11, 181,
So far i have written the below, this creates a plot for a month set in the date range. I am generally happy with how this plot looks except i need to fix the x axis labels.
I would like to loop through the whole dataset and create a pdf plot for each month. Any help with doing this would be appreciated!
import glob, os
import pandas as pd
from pandas import Series, DataFrame, Panel
import numpy as np
import matplotlib.pyplot as plt
wind = pd.read_csv('2014.csv')
wind['Date']=pd.to_datetime(wind['Date'])
wind=wind.set_index('Date')
dates = pd.date_range('2014-01', '2014-2', freq='1min')
janwin = Series(wind['Speed'], index=dates)
jandir = Series(wind['Dir'], index=dates)
plt.figure(1)
plt.subplot(211)
plt.plot(dates, janwin)
plt.ylabel("Km/hr")
plt.rcParams.update({'font.size': 4})
plt.grid(which='major', alpha = .5)
plt.subplot(212)
plt.plot(dates, jandir)
plt.ylabel("Degrees")
plt.rcParams.update({'font.size': 4})
plt.grid(which='major', alpha = 5)
plt.ylim(0,360)
plt.axis(minor=True)
plt.savefig('test.pdf', dpi=900)