Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- import pandas as pd
- #import math
- import numpy as np
- import matplotlib.pyplot as plt
- # download and process data
- relevant = pd.io.parsers.read_csv('http://hasan.d8u.us/links.py.cgi?format=csv')
- data = np.zeros_like(relevant)
- for i, t in enumerate(relevant['Timestamp']):
- data[i] = int(datetime.datetime.fromtimestamp(t).strftime('%H'))
- # histogram
- bins = np.arange(0, 25) # hours of the day
- hist = np.histogram(data, bins)[0]
- # plot
- fig = plt.figure(figsize=(6, 4.5), dpi=120)
- ax = fig.add_subplot(111)
- bar_width = 0.8
- hours = bins[:-1] - bar_width * 0.5 # discard last bin boundary and move bars
- ax.bar(hours, hist, bar_width, color='#2040ff', lw=0.8)
- ax.set_xlabel('Hour of day')
- ax.set_xlim(-1, 24)
- ax.set_xticks(range(0, 24, 3))
- ax.set_title('What hour were links sent out?', y=1.03)
- plt.savefig('barplot.png', dpi=400)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement