Created
February 10, 2014 00:27
-
-
Save crowsonkb/8908256 to your computer and use it in GitHub Desktop.
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 datetime | |
from matplotlib import dates as mpl_dates | |
import matplotlib.font_manager | |
from pylab import figure | |
import scipy.ndimage.filters as filters | |
fontfamily = ["Arial"] | |
dpi = 200.0 | |
fig = figure(figsize=(1280.0/dpi, 1280.0/1.6/dpi), dpi=dpi) | |
ax = fig.add_subplot(111) | |
dates = [] | |
weights = [] | |
with open("weight.txt") as f: | |
for line in f: | |
ss = line.split() | |
if len(ss) < 2: break | |
dc = ss[0].split("/") | |
if len(dc) < 2: break | |
dates.append(datetime.datetime(2013, int(dc[0]), int(dc[1]))) | |
weights.append(float(ss[1])) | |
fig.suptitle(u"Kat\u2019s weight over time", | |
family=fontfamily, size="large", weight="bold") | |
ax.set_xlabel("Date", family=fontfamily, weight="bold") | |
ax.set_xlim(min(dates) - datetime.timedelta(days=1), | |
max(dates) + datetime.timedelta(days=1)) | |
fmt = mpl_dates.DateFormatter("%m/%d") | |
ax.xaxis.set_major_formatter(fmt) | |
ax.set_ylabel("Weight (lb)", family=fontfamily, weight="bold") | |
ax.set_ylim(200, 240) | |
ax.grid(axis="y", linestyle="-", color="#cccccc") | |
smoothed = filters.gaussian_filter1d(weights, 2, mode="nearest") | |
ax.plot_date(dates, smoothed, "-", color="#d63632") | |
ax.plot_date(dates, weights, "-", color="#1344fc") | |
for tick in ax.xaxis.get_ticklabels(): | |
tick.set_family(fontfamily) | |
for tick in ax.yaxis.get_ticklabels(): | |
tick.set_family(fontfamily) | |
fig.savefig("weight.png", dpi=dpi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment