Skip to content

Instantly share code, notes, and snippets.

@wmoreland
Last active March 21, 2019 14:23
Show Gist options
  • Save wmoreland/e4bd27538f06e891be319fa650e5d347 to your computer and use it in GitHub Desktop.
Save wmoreland/e4bd27538f06e891be319fa650e5d347 to your computer and use it in GitHub Desktop.
Python Matplotlib plot of RevokeArticle50 petition data
Date Value
2019-03-20 21:19 122306
2019-03-20 21:22 124525
2019-03-20 21:26 127012
2019-03-20 21:32 130412
2019-03-20 21:34 131431
2019-03-20 21:36 133435
2019-03-20 21:38 135150
2019-03-20 21:40 137503
2019-03-20 21:42 140531
2019-03-20 21:43 141355
2019-03-20 21:45 143948
2019-03-20 21:48 147582
2019-03-20 21:52 152957
2019-03-20 21:58 159598
2019-03-20 22:00 162676
2019-03-20 22:03 167226
2019-03-20 22:07 172925
2019-03-20 22:11 178481
2019-03-20 22:14 182697
2019-03-20 22:19 189488
2019-03-20 22:21 192281
2019-03-20 22:24 196400
2019-03-20 22:36 212625
2019-03-20 22:42 220290
2019-03-20 22:44 222858
2019-03-20 22:46 225603
2019-03-20 22:48 228476
2019-03-20 22:50 231261
2019-03-20 22:52 233955
2019-03-20 22:54 236625
2019-03-20 22:56 239219
2019-03-20 22:59 243101
2019-03-20 23:01 245589
2019-03-20 23:04 249199
2019-03-20 23:07 252584
2019-03-20 23:10 256094
2019-03-20 23:19 265961
2019-03-20 23:21 268116
2019-03-20 23:27 274611
2019-03-20 23:29 276741
2019-03-20 23:41 288389
2019-03-20 23:43 290195
2019-03-20 23:45 291881
2019-03-20 23:53 298537
2019-03-20 23:56 300754
2019-03-21 00:00 303489
2019-03-21 00:02 305345
2019-03-21 00:05 307373
2019-03-21 00:07 308649
2019-03-21 00:09 309960
2019-03-21 00:10 310000
2019-03-21 02:07 343512
2019-03-21 07:37 467633
2019-03-21 08:42 588553
2019-03-21 08:52 612544
2019-03-21 09:15 619380
2019-03-21 09:40 631044
2019-03-21 09:42 637692
2019-03-21 10:05 662016
2019-03-21 10:20 696198
2019-03-21 10:27 696204
2019-03-21 11:07 734690
2019-03-21 11:17 747714
2019-03-21 11:43 776886
2019-03-21 11:49 779717
2019-03-21 12:05 810121
2019-03-21 12:30 834662
2019-03-21 12:36 840540
2019-03-21 12:53 861112
2019-03-21 13:08 879638
2019-03-21 13:12 884596
2019-03-21 13:17 890311
2019-03-21 13:32 908385
import numpy as np
import pandas as pd
import seaborn as sns
from matplotlib import dates
import matplotlib.pyplot as plt
sns.set(style='darkgrid')
df = pd.read_csv('petition_time.csv',
parse_dates=[0])
df['Date'] = pd.to_datetime(df['Date'], format='%Y-%m-%d %H:%M:%S')
df['Value'] = df['Value'] / 1000
sample = 17
# Number of new signatures in the past 20 measurements
dy = (df['Value'].tail(sample).max() - df['Value'].tail(sample).min()) * 1000
# Time past during the past 20 measurements in seconds
dx = ((df['Date'].tail(sample).max() - df['Date'].tail(sample).min()) / np.timedelta64(1, 's'))
dx_hrs = ((df['Date'].tail(sample).max() - df['Date'].tail(sample).min()) / np.timedelta64(1, 'h'))
fig, ax = plt.subplots(figsize=(10,6))
ax.plot(df['Date'], df['Value'], marker='x', linewidth=0, markeredgewidth=1.5,
markeredgecolor='k')
days = dates.DateFormatter('\n%d %b\n%Y')
hours = dates.DateFormatter('%H')
ax.xaxis.set_major_locator(dates.DayLocator())
ax.xaxis.set_minor_locator(dates.HourLocator())
ax.xaxis.set_major_formatter(days)
ax.xaxis.set_minor_formatter(hours)
ax.set_xlabel('Time (GMT)')
ax.set_ylabel('Number of signatures ($×10^3$)')
ax.set_xlim('2019-03-20 21:00', '2019-03-21 15:00')
ax.set_ylim(100, 1000)
ax.text('2019-03-21 00:00', 825,
'Last {:.1f} hours, {:.0f} signatures per second'.format(dx_hrs, round(dy/dx, -1)),
fontsize=18)
ax.grid(True, which='minor')
plt.savefig('petition_time.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment