Created
March 27, 2012 13:45
-
-
Save bilalhusain/2216007 to your computer and use it in GitHub Desktop.
hourly frequency plot using python matplotlib
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
#!/usr/bin/env python | |
import numpy as np | |
import matplotlib.mlab as mlab | |
import matplotlib.pyplot as plt | |
from datetime import datetime, tzinfo, timedelta | |
# a class to implement abstract tzinfo | |
class Zone(tzinfo): | |
def __init__(self, offset, isdst, name): | |
self.offset = offset | |
self.isdst = isdst | |
self.name = name | |
def utcoffset(self, dt): | |
return timedelta(hours=self.offset) + self.dst(dt) | |
def dst(self, dt): | |
return timedelta(hours=1) if self.isdst else timedelta(0) | |
def tzname(self, dt): | |
return self.name | |
GMT = Zone(0,False,'GMT') | |
stamps = [] | |
f = open('epochStamps.txt') # contains seconds since epoch corresponding to an event per line | |
epochstart = datetime(1970, 1, 1, tzinfo=GMT) | |
periodstart = datetime(2012, 3, 26, tzinfo=GMT) # lets say data is for 26th march | |
startstamp = int(timedelta.total_seconds(periodstart - epochstart)) | |
for line in f.readlines(): | |
stamp = int(line.strip()) | |
stamps.append(stamp - startstamp) # day start is 0, day end is 86400 | |
f.close() | |
n, bins, patches = plt.hist(stamps, 24) # hourly bins | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment