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 __future__ import division, print_function, absolute_import | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib.patches import Arc | |
from matplotlib.collections import PatchCollection | |
__all__ = ['arcs'] | |
def arcs(x, y, w, h=None, rot=0.0, theta1=0.0, theta2=360.0, | |
c='b', vmin=None, vmax=None, **kwargs): |
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
def siground(x, n): | |
from math import log10, floor | |
x, n = float(x), int(n) | |
assert n > 0 | |
if x == 0: | |
return ("%%.%if" % (n - 1)) % x | |
m = 10 ** floor(log10(abs(x))) | |
x = round(x / m, n - 1) * m | |
p = floor(log10(abs(x))) |
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
def mid(x, base=None): | |
'''Return mean value of adjacent member of an array. | |
Useful for plotting bin counts. | |
''' | |
if base is None: | |
x = np.asarray(x) | |
return (x[1:] + x[:-1])/2. | |
elif base == 'log': | |
return np.exp(mid(np.log(x))) | |
elif base == 'exp': |
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
def quantile(a, q=None, nsig=None, weights=None, sorted=False, nmin=0): | |
''' | |
nmin: int | |
Set `nmin` if you want a more reliable result. | |
Return `nan` when the tail probability is less than `nmin/a.size`. | |
''' | |
import numpy as np | |
from scipy.stats import norm | |
a = np.asarray(a) |
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 | |
__all__ = ["EqualGridInterpolator"] | |
class EqualGridInterpolator(object): | |
""" | |
Interpolation on a equal spaced regular grid in arbitrary dimensions. | |
Fock from https://github.com/JohannesBuchner/regulargrid |
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
def findroot(y0, x, y): | |
""" | |
y0: scalar | |
x: 1D array | |
y: function or 1D array | |
""" | |
import numpy as np | |
x = np.asarray(x) | |
assert x.ndim == 1 | |
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 pyplot as plt | |
def twin(show="xy", ax=None): | |
""" | |
Call signature:: | |
ax = twin() | |
create a twin of Axes for generating a plot with a shared | |
x-axis and y-axis. | |
The x-axis (y-axis) of ax will have ticks on bottom (left) |
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 __future__ import division, print_function, absolute_import | |
import warnings | |
import numpy as np | |
from collections import namedtuple | |
BinStats = namedtuple('BinStats', | |
('stats', 'bin_edges', 'bin_count')) | |
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 | |
from matplotlib import pyplot as plt | |
def hist_stats(x, y, bins=10, func=np.mean, nmin=None, **kwds): | |
""" | |
x = np.random.rand(1000) | |
hist_stats(x, x, func=lambda x:np.percentile(x, [15,50,85]), | |
ls=['--', '-', '--'], lw=[1, 2, 1]) | |
""" | |
stats, edges, count = binstats(x, y, bins=bins, func=func, nmin=nmin) |
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 __future__ import division | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib.lines import Line2D | |
__all__ = ["abline", "ABLine2D"] | |
def abline(a, b, *args, **kwargs): | |
""" |
OlderNewer