# What this gist provides:
tic()
'''code to be timed'''
toc()
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 numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as dates | |
import matplotlib.gridspec as gridspec | |
from datetime import timedelta, datetime, date | |
import GmailAccount # my package | |
gmail = GmailAccount(username='[email protected]', password=password) |
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
from imaplib import IMAP4_SSL | |
import email as em | |
from email.utils import parsedate, parsedate_tz | |
from email.parser import HeaderParser | |
class GmailAccount(object): | |
def __init__(self, username=None, password=None, folder=None): | |
self.username = username | |
self.password = password | |
self.folder = folder |
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
fig = plt.figure(figsize=(18,12)) | |
# Plotting across the international dateline is tough. One option is to break up flights | |
# by hemisphere. Otherwise, you'd need to plot using a different projection like 'robin' | |
# and potentially center on the Int'l Dateline (lon_0=-180) | |
# flights = flights[(flights.startlon < 0) & (flights.endlon < 0)]# Western Hemisphere Flights | |
# flights = flights[(flights.startlon > 0) & (flights.endlon > 0)] # Eastern Hemisphere Flights | |
xbuf = 0.2 | |
ybuf = 0.35 |
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
"""PLOT A HEXBIN MAP OF LOCATION | |
""" | |
figwidth = 14 | |
fig = plt.figure(figsize=(figwidth, figwidth*h/w)) | |
ax = fig.add_subplot(111, axisbg='w', frame_on=False) | |
# draw neighborhood patches from polygons | |
df_map['patches'] = df_map['poly'].map(lambda x: PolygonPatch( | |
x, fc='#555555', ec='#555555', lw=1, alpha=1, zorder=0)) | |
# plot neighborhoods by adding the PatchCollection to the axes instance |
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
# Check out the full post at http://beneathdata.com/how-to/visualizing-my-location-history/ | |
# to utilize the code below | |
# We'll only use a handful of distinct colors for our choropleth. So pick where | |
# you want your cutoffs to occur. Leave zero and ~infinity alone. | |
breaks = [0.] + [4., 24., 64., 135.] + [1e20] | |
def self_categorize(entry, breaks): | |
for i in range(len(breaks)-1): | |
if entry > breaks[i] and entry <= breaks[i+1]: | |
return i |