Package topo :: Package command :: Module pylabplot
[hide private]
[frames] | no frames]

Module pylabplot

source code

Line-based and matrix-based plotting commands using MatPlotLib.

Before importing this file, you will probably want to do something like:

from matplotlib import rcParams rcParams['backend']='TkAgg'

to select a backend, or else select an appropriate one in your matplotlib.rc file (if any). There are many backends available for different GUI or non-GUI uses.

$Id: pylabplot.py 11307 2010-07-27 16:40:49Z ceball $


Version: $Revision: 11307 $

Classes [hide private]
  ParameterizedFunction
Acts like a Python function, but with arguments that are Parameters.
  normalize_path
Convert a UNIX-style path to the current OS's format, typically for creating a new file or directory.
  PositionMeasurementCommand
Parameterized command for measuring topographic position.
  FeatureCurveCommand
A callable Parameterized command for measuring tuning curves.
  UnitCurveCommand
Measures tuning curve(s) of particular unit(s).
  Command
Parameterized command: any error when the command is run (called) will not raise an exception, but will instead generate a warning.
  PylabPlotCommand
Parameterized command for plotting using Matplotlib/Pylab.
  vectorplot
Simple line plotting for any vector or list of numbers.
  matrixplot
Simple plotting for any matrix as a bitmap with axes.
  matrixplot3d
Simple plotting for any matrix as a 3D wireframe with axes.
  histogramplot
Compute and plot the histogram of the supplied data.
  gradientplot
Compute and show the gradient plot of the supplied data.
  fftplot
Compute and show the 2D Fast Fourier Transform (FFT) of the supplied data.
  activityplot
Plots the activity in a sheet.
  topographic_grid
By default, plot the XPreference and YPreference preferences for all Sheets for which they are defined, using MatPlotLib.
  overlaid_plots
Use matplotlib to make a plot combining a bitmap and line-based overlays.
  tuning_curve
Plot a tuning curve for a feature, such as orientation, contrast, or size.
  cyclic_tuning_curve
Same as tuning_curve, but rotates the curve so that minimum y values are at the minimum x value to make the plots easier to interpret.
  plot_tracked_attributes
Plots parameter values associated with an AttributeTrackingTF.
  plot_modulation_ratio
This function computes the modulation ratios of neurons in the specified sheets and plots their histograms.
  measure_position_pref
Measure a position preference map by collating the response to patterns.
  measure_cog
Calculate center of gravity (CoG) for each CF of each unit in each CFSheet.
  measure_or_tuning_fullfield
Measures orientation tuning curve(s) of a particular unit using a full-field sine grating stimulus.
  measure_or_tuning
Measures orientation tuning curve(s) of a particular unit.
  measure_size_response
Measure receptive field size of one unit of a sheet.
  measure_contrast_response
Measures contrast response curves for a particular unit.
  measure_orientation_contrast
Measures the response to a center sine grating disk and a surround sine grating ring at different contrasts of the central disk.
  test_measure
  v
Parameterized command for plotting using Matplotlib/Pylab.
Functions [hide private]
 
array(sequence, typecode=None, copy=1, savespace=0, dtype=None)
 
transpose(a, axes=None)
Permute the dimensions of an array.
 
argmin(x, axis=-1)
 
outer(a, b)
Returns the outer product of two vectors.
 
ones(shape, dtype=None, order='C')
Return a new array of given shape and type, filled with ones.
 
fft2(a, s=None, axes=(-2, -1))
Compute the 2-dimensional discrete Fourier Transform
 
fftshift(x, axes=None)
Shift zero-frequency component to center of spectrum.
 
centroid(array_2D)
Return the centroid (center of gravity) for a 2D array.
source code
 
wrap(lower, upper, x)
Circularly alias the numeric value x into the range [lower,upper).
source code
 
frange(start, end=None, inc=1.0, inclusive=False)
A range function that accepts float increments.
source code
 
make_template_plot(channels, sheet_views, density=None, plot_bounding_box=None, normalize='None', name='None', range_=False)
Factory function for constructing a Plot object whose type is not yet known.
source code
 
create_plotgroup(template_plot_type='bitmap', **params)
Create a new PlotGroup and add it to the plotgroups list.
source code
 
matrixplot3d_gnuplot(mat, title=None, outputfilename='tmp.ps')
Simple plotting for any matrix as a 3D surface with axes.
source code
 
plot_cfproj_mapping(dest, proj='Afferent', style='b-')
Given a CF sheet receiving a CFProjection, plot the mapping of the dests CF centers on the src sheet.
source code
 
plot_coord_mapping(mapper, sheet, style='b-')
Plot a coordinate mapping for a sheet.
source code
Variables [hide private]
  ImportErrorRaisingFakeModule
  pi = 3.14159265359
  sqrt = <ufunc 'sqrt'>
  cos = <ufunc 'cos'>
  sin = <ufunc 'sin'>
  log10 = <ufunc 'log10'>
  Float = 'd'
  abs = <ufunc 'absolute'>
  pg = TemplatePlotGroup(auto_refresh=False, category='Preferenc...
  __package__ = 'topo.command'
  k = 'PylabPlotCommand'
Function Details [hide private]

transpose(a, axes=None)

 

Permute the dimensions of an array.

Parameters

a : array_like
Input array.
axes : list of ints, optional
By default, reverse the dimensions, otherwise permute the axes according to the values given.

Returns

p : ndarray
a with its axes permuted. A view is returned whenever possible.

See Also

rollaxis

Examples

>>> x = np.arange(4).reshape((2,2))
>>> x
array([[0, 1],
       [2, 3]])
>>> np.transpose(x)
array([[0, 2],
       [1, 3]])
>>> x = np.ones((1, 2, 3))
>>> np.transpose(x, (1, 0, 2)).shape
(2, 1, 3)

outer(a, b)

 

Returns the outer product of two vectors.

Given two vectors, [a0, a1, ..., aM] and [b0, b1, ..., bN], the outer product becomes:

[[a0*b0  a0*b1 ... a0*bN ]
 [a1*b0    .
 [ ...          .
 [aM*b0            aM*bN ]]

Parameters

a : array_like, shaped (M,)
First input vector. If either of the input vectors are not 1-dimensional, they are flattened.
b : array_like, shaped (N,)
Second input vector.

Returns

out : ndarray, shaped (M, N)
out[i, j] = a[i] * b[j]

Notes

The outer product of vectors is a special case of the Kronecker product.

Examples

>>> x = np.array(['a', 'b', 'c'], dtype=object)
>>> np.outer(x, [1, 2, 3])
array([[a, aa, aaa],
       [b, bb, bbb],
       [c, cc, ccc]], dtype=object)

ones(shape, dtype=None, order='C')

 

Return a new array of given shape and type, filled with ones.

Please refer to the documentation for zeros.

See Also

zeros

Examples

>>> np.ones(5)
array([ 1.,  1.,  1.,  1.,  1.])
>>> np.ones((5,), dtype=np.int)
array([1, 1, 1, 1, 1])
>>> np.ones((2, 1))
array([[ 1.],
       [ 1.]])
>>> s = (2,2)
>>> np.ones(s)
array([[ 1.,  1.],
       [ 1.,  1.]])

fft2(a, s=None, axes=(-2, -1))

 

Compute the 2-dimensional discrete Fourier Transform

This function computes the *n*-dimensional discrete Fourier Transform
over any axes in an *M*-dimensional array by means of the
Fast Fourier Transform (FFT).  By default, the transform is computed over
the last two axes of the input array, i.e., a 2-dimensional FFT.

Parameters
----------
a : array_like
    Input array, can be complex
s : sequence of ints, optional
    Shape (length of each transformed axis) of the output
    (`s[0]` refers to axis 0, `s[1]` to axis 1, etc.).
    This corresponds to `n` for `fft(x, n)`.
    Along each axis, if the given shape is smaller than that of the input,
    the input is cropped.  If it is larger, the input is padded with zeros.
    if `s` is not given, the shape of the input (along the axes specified
    by `axes`) is used.
axes : sequence of ints, optional
    Axes over which to compute the FFT.  If not given, the last 2
    axes are used.  A repeated index in `axes` means the transform over
    that axis is performed multiple times.  A one-element sequence means
    that a one-dimensional FFT is performed.

Returns
-------
out : complex ndarray
    The truncated or zero-padded input, transformed along the axes
    indicated by `axes`, or the last two axes if `axes` is not given.

Raises
------
ValueError
    if `s` and `axes` have different length, or
    `axes` not given and `len(s) != 2`
IndexError
    if an element of `axes` is larger than than the number of axes of `a`.

See Also
--------
numpy.fft : Overall view of discrete Fourier transforms, with definitions
     and conventions used.
ifft2 : The inverse two-dimensional FFT
fft : The one-dimensional FFT
fftn : The *n*-dimensional FFT
fftshift : shifts zero-frequency terms to centre of array.
    For two-dimensional input, swaps first and third quadrants, and second
    and fourth quadrants.

Notes
-----

`fft2` is just `fftn` with a different default for `axes`.

The output, analogously to `fft`, contains the term for zero frequency in
the low-order corner of the transformed axes, the positive frequency terms
in the first half of these axes, the term for the Nyquist frequency in the
middle of the axes and the negative frequency terms in the second half of
the axes, in order of decreasingly negative frequency.

See `fftn` for details and a plotting example, and `numpy.fft` for
definitions and conventions used.


Examples
--------
>>> from numpy import mgrid
>>> from numpy.fft import fft2
>>> a = mgrid[:5, :5][0]
>>> fft2(a)
array([[  0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j],
       [  5.+0.j,   0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j],
       [ 10.+0.j,   0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j],
       [ 15.+0.j,   0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j],
       [ 20.+0.j,   0.+0.j,   0.+0.j,   0.+0.j,   0.+0.j]])

fftshift(x, axes=None)

 

Shift zero-frequency component to center of spectrum.

This function swaps half-spaces for all axes listed (defaults to all). If len(x) is even then the Nyquist component is y[0].

Parameters

x : array_like
Input array.
axes : int or shape tuple, optional
Axes over which to shift. Default is None which shifts all axes.

See Also

ifftshift

wrap(lower, upper, x)

source code 

Circularly alias the numeric value x into the range [lower,upper).

Valid for cyclic quantities like orientations or hues.

frange(start, end=None, inc=1.0, inclusive=False)

source code 

A range function that accepts float increments.

Otherwise, works just as the inbuilt range() function. If inclusive is False, as in the default, the range is exclusive (not including the end value), as in the inbuilt range(). If inclusive is true, the range may include the end value.

'All theoretic restrictions apply, but in practice this is more useful than in theory.'

From: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66472

make_template_plot(channels, sheet_views, density=None, plot_bounding_box=None, normalize='None', name='None', range_=False)

source code 

Factory function for constructing a Plot object whose type is not yet known.

Typically, a TemplatePlot will be constructed through this call, because it selects the appropriate type automatically, rather than calling one of the Plot subclasses automatically. See TemplatePlot.__init__ for a description of the arguments.

create_plotgroup(template_plot_type='bitmap', **params)

source code 

Create a new PlotGroup and add it to the plotgroups list.

Convenience function to make it simpler to use the name of the PlotGroup as the key in the plotgroups list.

template_plot_type: Whether the plots are bitmap images or curves ('curve').

matrixplot3d_gnuplot(mat, title=None, outputfilename='tmp.ps')

source code 

Simple plotting for any matrix as a 3D surface with axes.

Currently requires the gnuplot-py package to be installed, plus the external gnuplot program; likely to be removed once Matplotlib supports 3D plots better.

Unlikely to work on non-UNIX systems.

Should return when it completes, but for some reason the Topographica prompt is not available until this command finishes.

plot_coord_mapping(mapper, sheet, style='b-')

source code 

Plot a coordinate mapping for a sheet.

Given a CoordinateMapperFn (as for a CFProjection) and a sheet of the projection, plot a grid showing where the sheet's units are mapped.


Variables Details [hide private]

pg

Value:
TemplatePlotGroup(auto_refresh=False, category='Preference Maps', desired_maximum_\
plot_height=0, doc='Measure the center of gravity of each ConnectionField in a Pro\
jection.', enforce_minimum_plot_height=True, integer_scaling=False, name='Center o\
f Gravity', normalize='Individually', plot_hooks=[topographic_grid(axis=[-0.5, 0.5\
, -0.5, 0.5], file_dpi=100.0, file_format='png', filename=None, filename_suffix=''\
, name='topographic_grid00125', print_level=100, title=None, xsheet_view_name='XCo\
G', ysheet_view_name='YCoG')], plot_immediately=False, pre_plot_hooks=[measure_cog\
(name='measure_cog00124', print_level=100, proj_name='')], prerequisites=[], print\
...