Created
March 6, 2015 13:24
-
-
Save aniversarioperu/c238e757fd513a66eec0 to your computer and use it in GitHub Desktop.
Script para plotear número de fotos del Congreso por fecha, agrupando por años, meses, etc.
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 itertools as it | |
import datetime | |
import numpy as np | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
def group_by_days(dates, ndays): | |
x_labels = [] | |
y_values = [] | |
for i, grp in it.groupby(dates, lambda i: (i.date() - dates[0].date()).days // ndays): | |
j = 0 | |
semana = list(grp) | |
x_labels.append(semana[0].date()) | |
y_values.append(len(semana)) | |
return x_labels, y_values | |
with open("fechas_sorted.csv", "r") as handle: | |
dates = handle.readlines() | |
dates = [i.strip() for i in dates] | |
dates = [datetime.datetime.strptime(i, '%Y-%m-%d') for i in dates] | |
x_labels, y_values = group_by_days(dates, 180) | |
sns.set(style="white", context="talk") | |
rs = np.random.RandomState(7) | |
x = np.array(x_labels) | |
f, ax1 = plt.subplots(1, 1, figsize=(8, 6), sharex=True) | |
y1 = np.array(y_values) | |
sns.barplot(x, y1, ci=None, palette="BuGn_d", hline=.1, ax=ax1) | |
ax1.set_ylabel("Sequential") | |
sns.despine(bottom=True) | |
plt.xticks(rotation="90") | |
plt.setp(f.axes, yticks=[]) | |
plt.tight_layout(h_pad=3) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment