Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Joe Kington joferkington

🏠
Working from home
Block or report user

Report or block joferkington

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@joferkington
joferkington / projection.py
Created Dec 27, 2014
Spießbürger's stereonet: Fixed coordinate conversions. See http://stackoverflow.com/questions/27622007
View projection.py
import matplotlib
from matplotlib.axes import Axes
from matplotlib.patches import Circle
from matplotlib.path import Path
from matplotlib.ticker import NullLocator, Formatter, FixedLocator
from matplotlib.transforms import Affine2D, BboxTransformTo, Transform
from matplotlib.projections import register_projection
import matplotlib.spines as mspines
import matplotlib.axis as maxis
import matplotlib.pyplot as plt
@joferkington
joferkington / profile.sh
Created Apr 22, 2012
Brute force memory monitor
View profile.sh
# /bin/sh
# Setup
datfile=$(mktemp)
echo "ElapsedTime MemUsed" > $datfile
starttime=$(date +%s.%N)
# Run the specified command in the background
$@ &
View zmap2xyz.py
"""
Converts one or more zmap grids to ascii x,y,z tab-delimited files. Exported
files will be saved to the current directory with a ".xyz" extension and the
same file name as the original. Null grid values will not be included unless
the "--with_nulls" option is specified.
Usage:
zmap2xyz.py [options] INPUT_FILES...
Options:
@joferkington
joferkington / cards_that_do_not_fit_future_sight.py
Created Nov 30, 2018
How many MTG cards would not fit on a future sight border?
View cards_that_do_not_fit_future_sight.py
import json
# https://mtgjson.com/v4/json/AllCards.json.zip
with open('AllCards.json', 'r') as infile:
data = json.load(infile)
for name in data:
card = data[name]
cost = card.get('manaCost', '')
if cost.count('{') > 6:
@joferkington
joferkington / datacursor.py
Created Jan 22, 2012
Matplotlib data cursor
View datacursor.py
from matplotlib import cbook
class DataCursor(object):
"""A simple data cursor widget that displays the x,y location of a
matplotlib artist when it is selected."""
def __init__(self, artists, tolerance=5, offsets=(-20, 20),
template='x: %0.2f\ny: %0.2f', display_all=False):
"""Create the data cursor and connect it to the relevant figure.
*artists* is the matplotlib artist or sequence of artists that will be
selected.
View fast_kde.py
import numpy as np
import scipy.sparse
import scipy.ndimage
import scipy.stats
import scipy.signal
import matplotlib.pyplot as plt
def main():
x, y = generate_data(int(1e7))
@joferkington
joferkington / data.csv
Last active Dec 8, 2017
Example of distributing a stand-alone executable with matplotlib and cx_freeze
View data.csv
931 Oxfordshire 9314125 123255 Larkmead School Abingdon 125 124 20 SUPP 8
931 Oxfordshire 9314126 123256 John Mason School Abingdon 164 164 25 6 16
931 Oxfordshire 9314127 123257 Fitzharrys School Abingdon 150 149 9 0 11
931 Oxfordshire 9316076 123298 Our Lady's Abingdon Abingdon 57 57 SUPP SUPP 16
@joferkington
joferkington / rose.py
Last active Oct 27, 2017
Correctly fix azimuths >360 or <0
View rose.py
import itertools
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.collections import PatchCollection
import numpy as np
np.random.seed(1977)
def main():
azi = np.random.normal(20, 40, 1000)
@joferkington
joferkington / arrowed_spines.py
Created Oct 6, 2012
Arrows on the ends of spines for matplotlib
View arrowed_spines.py
import matplotlib.pyplot as plt
def arrowed_spines(ax=None, arrow_length=20, labels=('', ''), arrowprops=None):
xlabel, ylabel = labels
if ax is None:
ax = plt.gca()
if arrowprops is None:
arrowprops = dict(arrowstyle='<|-', facecolor='black')
for i, spine in enumerate(['left', 'bottom']):
View chunked_hdf.py
import sys
import h5py
def main():
data = read()
if sys.argv[1] == 'x':
x_slice(data)
elif sys.argv[1] == 'z':
z_slice(data)
You can’t perform that action at this time.