Skip to content

Instantly share code, notes, and snippets.

@aniversarioperu
Created March 6, 2015 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aniversarioperu/c238e757fd513a66eec0 to your computer and use it in GitHub Desktop.
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.
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