Skip to content

Instantly share code, notes, and snippets.

Working from home

Joe Kington joferkington

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 /
Created Aug 28, 2015
Lovely dynamic typing
import random
class BadIdea(object):
def __getattr__(self, key):
return random.randint(0, 1000)
def __setattr__(self, key, value):
x = BadIdea()
joferkington /
Created Feb 21, 2014
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))
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
View gist:0b858cecc1ee659dd0d8
pipeline = sklearn.pipeline.Pipeline([
('Replace nans',
('Scale data',
('Feature Selection',
SelectPercentile(f_regression, percentile=60)),
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 = > 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 /
Created Dec 27, 2014
Spießbürger's stereonet: Fixed coordinate conversions. See
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
View gist:bbadb22da6949a285f95
import matplotlib.pyplot as plt
import cPickle as pickle
def main():
fig, ax = plt.subplots()
ax.plot(range(10)), range(10))
fig2 = copy_figure(fig)
fig2.axes[0].plot(range(10)[::-1], color='red')
View gist:6789f086769527cc3157
import matplotlib.pyplot as plt
from matplotlib.transforms import Affine2D
import mpl_toolkits.axisartist.floating_axes as floating_axes
fig = plt.figure()
plot_extents = 0, 10, 0, 10
transform = Affine2D().rotate_deg(45)
helper = floating_axes.GridHelperCurveLinear(transform, plot_extents)
ax = floating_axes.FloatingSubplot(fig, 111, grid_helper=helper)
joferkington /
Created Mar 26, 2015
General example of the type of framework you need to efficiently implement drawable/draggable/deleteable artists in matplotlib.
import numpy as np
import matplotlib.pyplot as plt
class DrawDragPoints(object):
Demonstrates a basic example of the "scaffolding" you need to efficiently
blit drawable/draggable/deleteable artists on top of a background.
def __init__(self):
self.fig, = self.setup_axes()
You can’t perform that action at this time.