gridcells
  • Overview
    • What are grid cells
    • What does gridcells do
    • Download
    • Dependencies
    • Installation
    • License
    • References
  • Modules
    • gridcells.core.common - common/shared definitions
    • gridcells.core.arena - Defining arenas
    • gridcells.analysis.bumps - bump tracking
    • gridcells.analysis.fields - grid field related analysis
    • gridcells.analysis.info - Information-theoretical analysis
    • gridcells.analysis.registration - Positional data registration.
    • gridcells.analysis.signal - signal analysis
    • gridcells.analysis.spikes - spike train analysis
    • gridcells.plotting.fields - grid field related plotting
 
gridcells
  • Docs »
  • Modules »
  • gridcells.plotting.fields - grid field related plotting
  • Edit on GitHub

gridcells.plotting.fields - grid field related plotting¶

The fields module contains routines to create matplotlib plots of spatial firing fields and similar commonly used structures.

How to plot¶

The plotting is currently realized as a subclass of matplotlib.axes.Axes and is used via a projection="gridcells_arena" keyword argument. Since a custom Axes class is not part of standard matplotlib, before using the projection, you have to first register the plotting class with matplotlib by importing the plotting module:

import matplotlib.pyplot as plt
from gridcells.plotting import fields
from gridcells.core import SquareArena, Pair2D

Next, create an Axes object that you can plot to:

fig = plt.figure()
arena = SquareArena(100., Pair2D(1., 1.))
ax = fig.add_subplot(111, projection="gridcells_arena", arena=arena)

The add_subplot method takes a keyword argument projection="gridcells_arena" that specifies the type of Axes to use. Here, we also have to specify the arena parameter in the form of an Arena instance. In our case we have created a square arena with size 100x100 and a discretisation of 1x1 (in arbitrary units).

Next, for illustration purposes, we create a random spatial rate map with size compatible with the current arena, and plot to the axes, by calling spatial_rate_map():

sz = arena.getDiscretisation()
rate_map = np.random.rand(len(sz.x), len(sz.y))
ax.spatial_rate_map(rate_map)

Custom grid cell plotting Axes¶

GridArenaAxes(*args, **kwargs) A custom matplotlib Axes that allows to plot figures in the shape of arenas.
class gridcells.plotting.fields.GridArenaAxes(*args, **kwargs)[source]¶

Bases: Axes

A custom matplotlib Axes that allows to plot figures in the shape of arenas.

Methods:

fft2(rate_map[, scalebar, scaletext, fftn, ...]) Plot a 2D Fourier transform (power) of a spatial rate map.
spatial_rate_map(rate_map[, scalebar, ...]) Plot the spatial rate map in the specified arena.
spikes(spike_times, pos[, dotsize, ...]) Plot spike positions.

Create the axes.

Should not be used directly, but via the matplotlib projection keyword argument.

Parameters:

arena : Arena

Are that will be used for plotting. This has to be specified as a keyword argument to matplotlib’s Figure.add_subplot() or Figure.add_axes().

default_margin = 0.0¶

Default margin in axis coordinates

fft2(rate_map, scalebar=None, scaletext='$cm^{-1}$', fftn=None, subtractmean=True, **kwargs)[source]¶

Plot a 2D Fourier transform (power) of a spatial rate map.

Parameters:

rate_map : np.ndarray

The rate map as 2D array. Rows determine the Y coordinate, columns the X coordinate. Masked items will be ignored.

scalebar : float, optional

The length of the scale bar that will be plotted as horizontal line. Must be in data units.

scaletext : str, optional

Text after the scale bar number, i.e. units.

fftn : int, optional

Size of the array that the Fourier transform is actually computed from. If None it will be max(rate_map.shape). Otherwise the rate_map will be padded with zeros.

subtractmean : bool, optional

Whether to subtract the mean of the signal before computing the FFT. This will remove any constant component in the centre of the spectrogram.

kwargs : kwargs

Optional kwargs that will be passed to matplotlib’s pcolormesh.

name = 'gridcells_arena'¶

Name of the class used to register with matplotlib

spatial_rate_map(rate_map, scalebar=None, scaletext='cm', maxrate=True, g_score=None, maxrate_fs='xx-small', **kwargs)[source]¶

Plot the spatial rate map in the specified arena.

Parameters:

rate_map : np.ndarray

The rate map as 2D array. Rows determine the Y coordinate, columns the X coordinate. Masked items will be ignored.

scalebar : float, optional

The length of the scale bar that will be plotted as horizontal line. Must be in data units.

scaletext : str, optional

Text after the scale bar number, i.e. units.

maxrate : bool, optional

Whether to print the max firing rate (top right corner)

g_score : float, optional

Grid score for this spatial rate map. If None, plot nothing.

maxrate_fs : matplotlib font size identifier

Font size for maxrate.

kwargs : kwargs

Optional kwargs that will be passed to matplotlib’s pcolormesh.

spikes(spike_times, pos, dotsize=5, scalebar=None, scaletext='cm', **kwargs)[source]¶

Plot spike positions.

Both positions and spikes must be aligned!

Parameters:

spike_times : np.ndarray

Spike times to plot on top of the trajectories

pos : gridcells.Position2D

Positional data for the spike times.

dotsize : float

Size of spike dots.

scalebar : float, optional

The length of the scale bar that will be plotted as horizontal line. Must be in data units.

scaletext : str, optional

Text after the scale bar number, i.e. units.

kwargs : kwargs

Optional kwargs that will be passed to matplotlib’s plot functions (for the trajectories and spike dots).

Previous

© Copyright 2014, Lukas Solanka.

Built with Sphinx using a theme provided by Read the Docs.