Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

# Joe Kingtonjoferkington

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

• Sort options
Created Aug 28, 2015
Lovely dynamic typing
View silly.py
 import random class BadIdea(object): def __getattr__(self, key): return random.randint(0, 1000) def __setattr__(self, key, value): pass x = BadIdea()
Created Feb 21, 2014
I'm having a bit too much fun with this...
View yo_dawg.py
 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)))
Created May 21, 2014
Outlines
View outline.py
 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
Last active Aug 29, 2015 — forked from anonymous/BenchMapCoordinates.py
View BenchMapCoordinates.py
 # -*- 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
Created Oct 14, 2014
View gist:0b858cecc1ee659dd0d8
 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,
Created Dec 2, 2014
View dashed_contours.py
 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
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
Created Jan 6, 2015
View gist:bbadb22da6949a285f95
 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.plot(range(10)[::-1], color='red')
Created Feb 9, 2015
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)
Created Mar 26, 2015
General example of the type of framework you need to efficiently implement drawable/draggable/deleteable artists in matplotlib.
View point_drag_add_delete.py
 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.ax = self.setup_axes()
You can’t perform that action at this time.