Skip to content

Instantly share code, notes, and snippets.

View baldwint's full-sized avatar

Tom Baldwin baldwint

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@baldwint
baldwint / scalebars.py
Last active August 29, 2015 14:01 — forked from dmeliza/scalebars.py
# -*- coding: utf-8 -*-
# -*- mode: python -*-
# Adapted from mpl_toolkits.axes_grid2
# LICENSE: Python Software Foundation (http://docs.python.org/license.html)
from matplotlib.offsetbox import AnchoredOffsetbox
class AnchoredScaleBar(AnchoredOffsetbox):
def __init__(self, transform, sizex=0, sizey=0, labelx=None, labely=None, loc=4,
pad=0.1, borderpad=0.1, sep=2, prop=None, **kwargs):
"""
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@baldwint
baldwint / sizebars.py
Created November 22, 2014 01:20
Convenience function for adding a horizontal scalebar (aka sizebar) to axes. For a vertical sizebar, see https://gist.github.com/dmeliza/3251476
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
def add_sizebar(ax, size, **kwargs):
kwargs.setdefault('label', str(size))
kwargs.setdefault('loc', 4)
asb = AnchoredSizeBar(ax.transData, size, **kwargs)
ax.add_artist(asb)
return asb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@baldwint
baldwint / bug.py
Created September 8, 2012 08:47
globaloptions bug in optster
#!/usr/bin/env python
"""
Demonstrates a bug in opster.
This is intended to have two subcommands, `edit` and `read`.
`read` takes a positional argument, `edit` takes none.
If you run the script as-is, like::
python bug.py edit