This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make up some data in nested lists | |
strain_data = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] | |
# To make things a bit more readable, let's define a function that operates | |
# on a single list... | |
def zero(data): | |
"""Returns the difference between the items in "data" and its first item.""" | |
# This is a "list comprehension". It's basically a 1-line for loop | |
return [item - data[0] for item in data] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /bin/sh | |
# Setup | |
datfile=$(mktemp) | |
echo "ElapsedTime MemUsed" > $datfile | |
starttime=$(date +%s.%N) | |
# Run the specified command in the background | |
$@ & |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def process_file(filename, num_cols, delimiter='\t'): | |
def items(infile): | |
for line in infile: | |
for item in line.rstrip().split(delimiter): | |
yield float(item) | |
with open(filename, 'r') as infile: | |
data = np.fromiter(items(infile)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""MIT license""" | |
import xlrd | |
import re | |
def col2index(name): | |
name = name.upper() | |
col = -1 | |
for i, letter in enumerate(name[::-1]): | |
col += (ord(letter) - ord('A') + 1) * 26**i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy.ndimage as ndimage | |
# The array you gave above | |
data = np.array( | |
[ | |
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
OlderNewer