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
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 / profile.sh
Created April 22, 2012 03:38
Brute force memory monitor
# /bin/sh
# Setup
datfile=$(mktemp)
echo "ElapsedTime MemUsed" > $datfile
starttime=$(date +%s.%N)
# Run the specified command in the background
$@ &
"""
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 November 30, 2018 16:27
How many MTG cards would not fit on a future sight border?
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 January 22, 2012 22:15
Matplotlib data cursor
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.
@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)
import numpy as np
from scipy.interpolate import Rbf
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
from mpl_toolkits.axes_grid1 import inset_locator
from matplotlib.projections.polar import PolarAxes
np.random.seed(1977)
def main():
x, y, z = generate_surface()
import Tkinter as tk
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
def main():
root = tk.Tk()
app = Application(root)
tk.mainloop()
import matplotlib.pyplot as plt
from matplotlib.widgets import MultiCursor
import numpy as np
class SynchedMultiCursor(MultiCursor):
def __init__(self, *args, **kwargs):
self._enabled = True
MultiCursor.__init__(self, *args, **kwargs)
def onmove(self, event):
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
num = 100000
x, y = np.random.random((2, num))
category = np.random.randint(1, 5, num)
# Using multiple "plot" calls
fig, ax = plt.subplots()