plotting

XY_scatter(x, y, xlim, ylim, min_n, dof[, ...])
beta_hist(beta, xlim, voxel_dim, plot_color, ...)
eccentricity_hist(x, y, xlim, voxel_dim, dof)
eccentricity_sigma_fill(ecc, sigma, ...[, ...])
eccentricity_sigma_scatter(x, y, sigma, ...)
field_coverage(x, y, s, deg_x, deg_y[, log, ...])
hexbin_location_map(x, y)
hrf_delay_hist(measure, bins, voxel_dim, dof)
hrf_delay_kde(delays, kernel_width, ...[, ...])
lazy_field_coverage(field[, log, polar])
location_and_size_map(x, y, s, plot_color)
location_estimate_jointdist(x, y, plot_color)
make_movie_calleable(stim_arr, dims, vmin, ...)
make_movie_static(stim_arr, dims[, vmin, ...])
polar_angle_plot(x, y, voxel_dim, ...[, ...])
sigma_hrf_delay_scatter(sigma, hrf_delay, ...)

Circle

class popeye.plotting.Circle(xy, radius=5, **kwargs)

Bases: matplotlib.patches.Ellipse

A circle patch.

__init__(xy, radius=5, **kwargs)

Create true circle at center xy = (x, y) with given radius. Unlike CirclePolygon which is a polygonal approximation, this uses Bézier splines and is much closer to a scale-free circle.

Valid kwargs are:
agg_filter: unknown alpha: float or None animated: [True | False] antialiased or aa: [True | False] or None for default axes: an Axes instance capstyle: [‘butt’ | ‘round’ | ‘projecting’] clip_box: a matplotlib.transforms.Bbox instance clip_on: [True | False] clip_path: [ (Path, Transform) | Patch | None ] color: matplotlib color spec contains: a callable function edgecolor or ec: mpl color spec, or None for default, or ‘none’ for no color facecolor or fc: mpl color spec, or None for default, or ‘none’ for no color figure: a matplotlib.figure.Figure instance fill: [True | False] gid: an id string hatch: [‘/’ | ‘\’ | ‘|’ | ‘-‘ | ‘+’ | ‘x’ | ‘o’ | ‘O’ | ‘.’ | ‘*’] joinstyle: [‘miter’ | ‘round’ | ‘bevel’] label: string or anything printable with ‘%s’ conversion. linestyle or ls: [‘solid’ | ‘dashed’, ‘dashdot’, ‘dotted’ | (offset, on-off-dash-seq) | '-' | '--' | '-.' | ':' | 'None' | ' ' | ''] linewidth or lw: float or None for default path_effects: unknown picker: [None|float|boolean|callable] rasterized: [True | False | None] sketch_params: unknown snap: unknown transform: Transform instance url: a url string visible: [True | False] zorder: any number
get_radius()

return the radius of the circle

radius

return the radius of the circle

set_radius(radius)

Set the radius of the circle

ACCEPTS: float

LogFormatterMathtext

class popeye.plotting.LogFormatterMathtext(base=10.0, labelOnlyBase=True)

Bases: matplotlib.ticker.LogFormatter

Format values for log axis; using exponent = log_base(value)

__init__(base=10.0, labelOnlyBase=True)

base is used to locate the decade tick, which will be the only one to be labeled if labelOnlyBase is False

LogNorm

class popeye.plotting.LogNorm(vmin=None, vmax=None, clip=False)

Bases: matplotlib.colors.Normalize

Normalize a given value to the 0-1 range on a log scale

__init__(vmin=None, vmax=None, clip=False)

If vmin or vmax is not given, they are initialized from the minimum and maximum value respectively of the first input processed. That is, __call__(A) calls autoscale_None(A). If clip is True and the given value falls outside the range, the returned value will be 0 or 1, whichever is closer. Returns 0 if:

vmin==vmax

Works with scalars or arrays, including masked arrays. If clip is True, masked values are set to 1; otherwise they remain masked. Clipping silently defeats the purpose of setting the over, under, and masked colors in the colormap, so it is likely to lead to surprises; therefore the default is clip = False.

autoscale(A)

Set vmin, vmax to min, max of A.

autoscale_None(A)

autoscale only None-valued vmin or vmax

inverse(value)

gaussian_kde

class popeye.plotting.gaussian_kde(dataset, bw_method=None)

Bases: object

Representation of a kernel-density estimate using Gaussian kernels.

Kernel density estimation is a way to estimate the probability density function (PDF) of a random variable in a non-parametric way. gaussian_kde works for both uni-variate and multi-variate data. It includes automatic bandwidth determination. The estimation works best for a unimodal distribution; bimodal or multi-modal distributions tend to be oversmoothed.

dataset : array_like
Datapoints to estimate from. In case of univariate data this is a 1-D array, otherwise a 2-D array with shape (# of dims, # of data).
bw_method : str, scalar or callable, optional
The method used to calculate the estimator bandwidth. This can be ‘scott’, ‘silverman’, a scalar constant or a callable. If a scalar, this will be used directly as kde.factor. If a callable, it should take a gaussian_kde instance as only parameter and return a scalar. If None (default), ‘scott’ is used. See Notes for more details.
dataset : ndarray
The dataset with which gaussian_kde was initialized.
d : int
Number of dimensions.
n : int
Number of datapoints.
factor : float
The bandwidth factor, obtained from kde.covariance_factor, with which the covariance matrix is multiplied.
covariance : ndarray
The covariance matrix of dataset, scaled by the calculated bandwidth (kde.factor).
inv_cov : ndarray
The inverse of covariance.
kde.evaluate(points) : ndarray
Evaluate the estimated pdf on a provided set of points.
kde(points) : ndarray
Same as kde.evaluate(points)
kde.integrate_gaussian(mean, cov) : float
Multiply pdf with a specified Gaussian and integrate over the whole domain.
kde.integrate_box_1d(low, high) : float
Integrate pdf (1D only) between two bounds.
kde.integrate_box(low_bounds, high_bounds) : float
Integrate pdf over a rectangular space between low_bounds and high_bounds.
kde.integrate_kde(other_kde) : float
Integrate two kernel density estimates multiplied together.
kde.resample(size=None) : ndarray
Randomly sample a dataset from the estimated pdf.
kde.set_bandwidth(bw_method=’scott’) : None
Computes the bandwidth, i.e. the coefficient that multiplies the data covariance matrix to obtain the kernel covariance matrix. .. versionadded:: 0.11.0
kde.covariance_factor : float
Computes the coefficient (kde.factor) that multiplies the data covariance matrix to obtain the kernel covariance matrix. The default is scotts_factor. A subclass can overwrite this method to provide a different method, or set it through a call to kde.set_bandwidth.

Bandwidth selection strongly influences the estimate obtained from the KDE (much more so than the actual shape of the kernel). Bandwidth selection can be done by a “rule of thumb”, by cross-validation, by “plug-in methods” or by other means; see [3], [4] for reviews. gaussian_kde uses a rule of thumb, the default is Scott’s Rule.

Scott’s Rule [1], implemented as scotts_factor, is:

n**(-1./(d+4)),

with n the number of data points and d the number of dimensions. Silverman’s Rule [2], implemented as silverman_factor, is:

n * (d + 2) / 4.)**(-1. / (d + 4)).

Good general descriptions of kernel density estimation can be found in [1] and [2], the mathematics for this multi-dimensional implementation can be found in [1].

[1](1, 2, 3) D.W. Scott, “Multivariate Density Estimation: Theory, Practice, and Visualization”, John Wiley & Sons, New York, Chicester, 1992.
[2](1, 2) B.W. Silverman, “Density Estimation for Statistics and Data Analysis”, Vol. 26, Monographs on Statistics and Applied Probability, Chapman and Hall, London, 1986.
[3]B.A. Turlach, “Bandwidth Selection in Kernel Density Estimation: A Review”, CORE and Institut de Statistique, Vol. 19, pp. 1-33, 1993.
[4]D.M. Bashtannyk and R.J. Hyndman, “Bandwidth selection for kernel conditional density estimation”, Computational Statistics & Data Analysis, Vol. 36, pp. 279-298, 2001.

Generate some random two-dimensional data:

>>> from scipy import stats
>>> def measure(n):
>>>     "Measurement model, return two coupled measurements."
>>>     m1 = np.random.normal(size=n)
>>>     m2 = np.random.normal(scale=0.5, size=n)
>>>     return m1+m2, m1-m2
>>> m1, m2 = measure(2000)
>>> xmin = m1.min()
>>> xmax = m1.max()
>>> ymin = m2.min()
>>> ymax = m2.max()

Perform a kernel density estimate on the data:

>>> X, Y = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]
>>> positions = np.vstack([X.ravel(), Y.ravel()])
>>> values = np.vstack([m1, m2])
>>> kernel = stats.gaussian_kde(values)
>>> Z = np.reshape(kernel(positions).T, X.shape)

Plot the results:

>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> ax.imshow(np.rot90(Z), cmap=plt.cm.gist_earth_r,
...           extent=[xmin, xmax, ymin, ymax])
>>> ax.plot(m1, m2, 'k.', markersize=2)
>>> ax.set_xlim([xmin, xmax])
>>> ax.set_ylim([ymin, ymax])
>>> plt.show()
__init__(dataset, bw_method=None)
covariance_factor()
evaluate(points)

Evaluate the estimated pdf on a set of points.

points : (# of dimensions, # of points)-array
Alternatively, a (# of dimensions,) vector can be passed in and treated as a single point.
values : (# of points,)-array
The values at each point.
ValueError : if the dimensionality of the input points is different than
the dimensionality of the KDE.
integrate_box(low_bounds, high_bounds, maxpts=None)

Computes the integral of a pdf over a rectangular interval.

low_bounds : array_like
A 1-D array containing the lower bounds of integration.
high_bounds : array_like
A 1-D array containing the upper bounds of integration.
maxpts : int, optional
The maximum number of points to use for integration.
value : scalar
The result of the integral.
integrate_box_1d(low, high)

Computes the integral of a 1D pdf between two bounds.

low : scalar
Lower bound of integration.
high : scalar
Upper bound of integration.
value : scalar
The result of the integral.
ValueError
If the KDE is over more than one dimension.
integrate_gaussian(mean, cov)

Multiply estimated density by a multivariate Gaussian and integrate over the whole space.

mean : aray_like
A 1-D array, specifying the mean of the Gaussian.
cov : array_like
A 2-D array, specifying the covariance matrix of the Gaussian.
result : scalar
The value of the integral.
ValueError :
If the mean or covariance of the input Gaussian differs from the KDE’s dimensionality.
integrate_kde(other)

Computes the integral of the product of this kernel density estimate with another.

other : gaussian_kde instance
The other kde.
value : scalar
The result of the integral.
ValueError
If the KDEs have different dimensionality.
resample(size=None)

Randomly sample a dataset from the estimated pdf.

size : int, optional
The number of samples to draw. If not provided, then the size is the same as the underlying dataset.
resample : (self.d, size) ndarray
The sampled dataset.
scotts_factor()
set_bandwidth(bw_method=None)

Compute the estimator bandwidth with given method.

The new bandwidth calculated after a call to set_bandwidth is used for subsequent evaluations of the estimated density.

bw_method : str, scalar or callable, optional
The method used to calculate the estimator bandwidth. This can be ‘scott’, ‘silverman’, a scalar constant or a callable. If a scalar, this will be used directly as kde.factor. If a callable, it should take a gaussian_kde instance as only parameter and return a scalar. If None (default), nothing happens; the current kde.covariance_factor method is kept.

New in version 0.11.

>>> x1 = np.array([-7, -5, 1, 4, 5.])
>>> kde = stats.gaussian_kde(x1)
>>> xs = np.linspace(-10, 10, num=50)
>>> y1 = kde(xs)
>>> kde.set_bandwidth(bw_method='silverman')
>>> y2 = kde(xs)
>>> kde.set_bandwidth(bw_method=kde.factor / 3.)
>>> y3 = kde(xs)
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> ax.plot(x1, np.ones(x1.shape) / (4. * x1.size), 'bo',
...         label='Data points (rescaled)')
>>> ax.plot(xs, y1, label='Scott (default)')
>>> ax.plot(xs, y2, label='Silverman')
>>> ax.plot(xs, y3, label='Const (1/3 * Silverman)')
>>> ax.legend()
>>> plt.show()
silverman_factor()

XY_scatter

popeye.plotting.XY_scatter(x, y, xlim, ylim, min_n, dof, plot_alpha=1.0, plot_color='k', label_name=None, show_legend=False, show_fit=False, fig=None, ax=None)

beta_hist

popeye.plotting.beta_hist(beta, xlim, voxel_dim, plot_color, label_name, fig=None, ax=None)

eccentricity_hist

popeye.plotting.eccentricity_hist(x, y, xlim, voxel_dim, dof, plot_alpha=1.0, plot_color='k', label_name=None, show_legend=False, fig=None, ax=None)

eccentricity_sigma_fill

popeye.plotting.eccentricity_sigma_fill(ecc, sigma, plot_color, label_name, fig=None, ax=None)

eccentricity_sigma_scatter

popeye.plotting.eccentricity_sigma_scatter(x, y, sigma, xlim, ylim, min_n, dof, plot_alpha=1.0, plot_color='k', label_name=None, show_legend=False, show_fit=False, fig=None, ax=None)

field_coverage

popeye.plotting.field_coverage(x, y, s, deg_x, deg_y, log=False, polar=False)

generate_og_receptive_field

popeye.plotting.generate_og_receptive_field()

Generate a Gaussian.

x : float
The x coordinate of the center of the Gaussian (degrees)
y : float
The y coordinate of the center of the Gaussian (degrees)
s : float
The dispersion of the Gaussian (degrees)
beta : float
The amplitude of the Gaussian
deg_x : 2D array
The coordinate matrix along the horizontal dimension of the display (degrees)
deg_y : 2D array
The coordinate matrix along the vertical dimension of the display (degrees)

Returns

stim : ndarray
The 1D array containing the stimulus energies given the Gaussian coordinates

hexbin_location_map

popeye.plotting.hexbin_location_map(x, y)

hrf_delay_hist

popeye.plotting.hrf_delay_hist(measure, bins, voxel_dim, dof, plot_alpha=1.0, plot_color='k', label_name=None, show_legend=False, fig=None, ax=None)

hrf_delay_kde

popeye.plotting.hrf_delay_kde(delays, kernel_width, plot_color, label_name, fig=None, ax=None)

lazy_field_coverage

popeye.plotting.lazy_field_coverage(field, log=False, polar=False)

linregress

popeye.plotting.linregress(x, y=None)

Calculate a regression line

This computes a least-squares regression for two sets of measurements.

x, y : array_like
two sets of measurements. Both arrays should have the same length. If only x is given (and y=None), then it must be a two-dimensional array where one dimension has length 2. The two sets of measurements are then found by splitting the array along the length-2 dimension.
slope : float
slope of the regression line
intercept : float
intercept of the regression line
r-value : float
correlation coefficient
p-value : float
two-sided p-value for a hypothesis test whose null hypothesis is that the slope is zero.
stderr : float
Standard error of the estimate
>>> from scipy import stats
>>> import numpy as np
>>> x = np.random.random(10)
>>> y = np.random.random(10)
>>> slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)

# To get coefficient of determination (r_squared)

>>> print "r-squared:", r_value**2
r-squared: 0.15286643777

location_and_size_map

popeye.plotting.location_and_size_map(x, y, s, plot_color)

location_estimate_jointdist

popeye.plotting.location_estimate_jointdist(x, y, plot_color)

make_movie_calleable

popeye.plotting.make_movie_calleable(stim_arr, dims, vmin, vmax, fps, bitrate, dpi, fname=None)

make_movie_static

popeye.plotting.make_movie_static(stim_arr, dims, vmin=0, vmax=255, dpi=100, fps=60, write=False, fname=None)

polar_angle_plot

popeye.plotting.polar_angle_plot(x, y, voxel_dim, num_radians, rlim, dof, plot_alpha=1.0, plot_color='k', label_name=None, show_legend=False, fig=None, ax=None)

sigma_hrf_delay_scatter

popeye.plotting.sigma_hrf_delay_scatter(sigma, hrf_delay, xlim, ylim, min_vox, n, plot_color, label_name, show_legend=False, fig=None, ax=None)