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
View datacursor_example_lookup.py
import random
import matplotlib.pyplot as plt
from mpldatacursor import datacursor
def main():
accounts = generate_accounts()
lookup = plot(accounts)
datacursor(formatter=Formatter(lookup), bbox=dict(alpha=1))
plt.show()
View datacursor_example_formatter_label.py
import random
import matplotlib.pyplot as plt
from mpldatacursor import datacursor
def main():
accounts = generate_accounts()
plot(accounts)
datacursor(formatter='Account #\n{label}'.format, bbox=dict(alpha=1))
plt.show()
@joferkington
joferkington / masked_hist.py
Created Jun 10, 2015
Quick example of masking 0-count portions of a 2D histogram
View masked_hist.py
import numpy as np
import matplotlib.pyplot as plt
x, y = np.random.normal(0, 1, (2, 1000))
counts, ybins, xbins = np.histogram2d(y, x, bins=30)
counts = np.ma.masked_equal(counts, 0)
fig, ax = plt.subplots()
ax.pcolormesh(xbins, ybins, counts)
@joferkington
joferkington / point_drag_add_delete.py
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()
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
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)
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[0].plot(range(10)[::-1], color='red')
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 / projection.py
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
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
You can’t perform that action at this time.