forked from tjburch/latex-progress-tracker
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotProgress.py
More file actions
109 lines (92 loc) · 3.95 KB
/
Copy pathplotProgress.py
File metadata and controls
109 lines (92 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from datetime import datetime
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import os
import sys
import numpy as np
import seaborn as sns
savedir = os.getcwd()+"/"
output_format = ".png"
df = pd.read_csv('progress.csv')
df['timestamp_fixed'] = pd.to_datetime(df['timestamp'], format="%Y-%m-%d %H:%M:%S")
df = df.set_index('timestamp_fixed')
current_pagecount = df["pagecount"].iloc[-1]
current_wordcount = df["wordcount"].iloc[-1]
wc_color="orangered"
pc_color="royalblue"
# Plot with Combined progress
months = mdates.MonthLocator() # every month
days = mdates.DayLocator() # every day
date_fmt = mdates.DateFormatter('%b %Y')
fig, ax = plt.figure(), plt.gca()
ax2= ax.twinx()
df.plot(y='pagecount',legend=None, ax=ax, color=pc_color)
df.plot(y='wordcount', legend=None, ax=ax2, color=wc_color)
ax.set_ylabel("Page Count", fontsize=16, color=pc_color)
ax2.set_ylabel("Word Count", fontsize=16,color=wc_color)
ax.set_xlabel('Date',fontsize=16)
ax.set_ylim(ymin=0)
ax2.set_ylim(ymin=0)
plt.annotate("{:,d} Pages".format(current_pagecount), xy=(.05,.88), xycoords="axes fraction",color=pc_color, fontsize=14)
plt.annotate("{:,d} Words".format(current_wordcount), xy=(.05,.8), xycoords="axes fraction",color=wc_color, fontsize=14)
#ax.xaxis.set_major_locator(months) Uncomment if you want month-level updates
ax.xaxis.set_minor_locator(days)
ax.xaxis.set_major_formatter(date_fmt)
# Uncomment if you want vertical lines at important points
"""
dates = {}
dates["Detector chapter \nsent for edits "] = "2019-09-22 15:30:00"
dates["Theory chapter \nsent for edits "] = "2019-10-20 21:57:00"
for title,dt in dates.items():
xloc = pd.to_datetime(dt)
ax.axvline(x=xloc, color='firebrick', linestyle='--',)
plt.annotate(title, xy=(xloc, 100), color="firebrick", fontsize=10, ha="right")
"""
ax.tick_params(labelsize=12)
ax2.tick_params(labelsize=12)
plt.tight_layout()
plt.savefig(savedir+"progress"+output_format)
# Twitter-friendly
fig = plt.gcf()
fig.set_size_inches(2*fig.get_figheight(),fig.get_figheight(),forward=True)
plt.savefig(savedir+"progress_twitter"+output_format)
plt.close()
##### Time Delta Plot ####
def make_pages_plot(axis):
df.plot(y='pagecount',legend=None, color=pc_color, ax=axis,label="Raw Data")
done_resample_df = df.resample('w').max()
done_resample_df['pagecount'].plot(figsize=(12,8), color='salmon',label="Rolling 7-day Max", ax=axis)
slope = pd.Series(np.gradient(done_resample_df["pagecount"].values), done_resample_df.index, name='slope')
plt.sca(axis)
plt.plot(done_resample_df['pagecount'].diff(), color="forestgreen",label="Rolling 7-Day Change")
plt.ylabel("Pages",fontsize=14)
plt.annotate("{:,d} Pages".format(current_pagecount), xy=(.05,.88), xycoords="axes fraction", fontsize=16)
def make_words_plot(axis):
df.plot(y='wordcount',legend=None, color=pc_color, ax=axis,label="Raw Data")
done_resample_df = df.resample('w').max()
done_resample_df['wordcount'].plot(figsize=(12,8), color='salmon',label="Rolling 7-day Max",ax=axis)
slope = pd.Series(np.gradient(done_resample_df["wordcount"].values), done_resample_df.index, name='slope')
plt.sca(axis)
plt.plot(done_resample_df['wordcount'].diff(), color="forestgreen",label="Rolling 7-Day Change")
plt.ylabel("Words",fontsize=14)
plt.annotate("{:,d} Words".format(current_wordcount), xy=(.05,.88), xycoords="axes fraction", fontsize=16)
def make_format():
sns.despine()
plt.ylim(bottom=0)
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)
fig, (ax1,ax2) = plt.subplots(ncols=1, nrows=2, sharex=True)
make_pages_plot(ax1)
make_format()
make_words_plot(ax2)
make_format()
plt.xlabel("Date",fontsize=14)
plt.legend(bbox_to_anchor=(1.2,1), loc="center",frameon=False,fontsize=14)
months = mdates.MonthLocator()
years_fmt = mdates.DateFormatter('%b %Y')
ax2.xaxis.set_major_locator(months)
ax2.xaxis.set_major_formatter(years_fmt)
plt.minorticks_off()
plt.tight_layout()
plt.savefig(savedir+"delta_plots"+output_format)