Skip to content

Instantly share code, notes, and snippets.

View joferkington's full-sized avatar
🏠
Working from home

Joe Kington joferkington

🏠
Working from home
View GitHub Profile
@joferkington
joferkington / yo_dawg.py
Created February 21, 2014 17:15
I'm having a bit too much fun with this...
import matplotlib.pyplot as plt
import numpy as np
def main():
t = np.linspace(0, 4*np.pi, 1000)
fig, ax = plt.subplots()
ax.plot(t, np.cos(t))
ax.plot(t, np.sin(t))
inception(inception(inception(fig)))
@joferkington
joferkington / data.csv
Last active March 20, 2021 11:37
Example of distributing a stand-alone executable with matplotlib and cx_freeze
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
import scipy.ndimage as ndimage
import numpy as np
import matplotlib.pyplot as plt
data = np.zeros((40,40), dtype=bool)
data[5:20, 5:20] = True
data[15:35, 15:35] = True
footprint = np.ones((3,3))
outside = ndimage.binary_dilation(data, structure=footprint) - data
# -*- coding: utf-8 -*-
"""
Benchmark for spline interpolation of a 3D wind field, using the function map_coordinates.
The spline interpolation is about 46000 times slower than a linear interpolation.
It is also about 10000 times slower than an equivalent program, written in the programming
language Julia.
"""
import time
import numpy as np
from scipy import ndimage
pipeline = sklearn.pipeline.Pipeline([
('Replace nans',
preprocessing.Imputer(strategy='mean')),
('Scale data',
preprocessing.StandardScaler()),
('Feature Selection',
SelectPercentile(f_regression, percentile=60)),
('Regression',
ensemble.ExtraTreesRegressor(
n_estimators=550,
import numpy as np
import matplotlib.pyplot as plt
x, y = np.mgrid[:10, :10]
z = np.hypot(x - 4.5, y - 4.5)
#-- Create two masked arrays, one with the upper region and one with the lower.
z1 = np.ma.masked_where(y > 5, z)
# If we just invert the previous masked region, we'll have a gap. There are
# better ways to do this, but for simple cases, we can just ensure a one-pixel
@joferkington
joferkington / projection.py
Created December 27, 2014 07:32
Spießbürger's stereonet: Fixed coordinate conversions. See http://stackoverflow.com/questions/27622007
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
import sys
import h5py
def main():
data = read()
if sys.argv[1] == 'x':
x_slice(data)
elif sys.argv[1] == 'z':
z_slice(data)
import matplotlib.pyplot as plt
import cPickle as pickle
def main():
fig, ax = plt.subplots()
ax.plot(range(10))
ax.bar(range(10), range(10))
fig2 = copy_figure(fig)
fig2.axes[0].plot(range(10)[::-1], color='red')
@joferkington
joferkington / rose.py
Last active October 27, 2017 02:24
Correctly fix azimuths >360 or <0
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)