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 / slice_explorer.py
Created May 31, 2013
Simple pcolormesh data explorer
View slice_explorer.py
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
def main():
data = np.random.random((10,10,10))
ex = Explorer(data)
ex.show()
class Explorer(object):
View scatter_vs_multiple_plot_calls.py
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()
View multicursor_multispan_demo.py
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):
View example_scrolling_plot.py
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()
View circular_colorbar_demo.py
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()
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)
@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']):
@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 / 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 / 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.
You can’t perform that action at this time.