tramway.plot package

tramway.plot.mesh module

tramway.plot.mesh.plot_points(cells, min_count=None, style='.', size=8, color=None, axes=None, **kwargs)

Plot 2D points coloured by associated cell.

Parameters:
  • cells (Partition or FiniteElements) – full partition
  • min_count (int) – discard cells with less than this number of associated points
  • style (str) – point marker style
  • size (int) – point marker size
  • color (str or numpy.ndarray) – cell colours
Returns:

handles of the various clouds of points

Return type:

list

Extra keyword arguments are passed to matplotlib ‘s scatter or plot.

tramway.plot.mesh.plot_voronoi(cells, labels=None, color=None, style='-', centroid_style='g+', negative=None, linewidth=1, fallback_color='gray', verbose=True, axes=None)

Voronoi plot.

Parameters:
  • cells (Partition) – full partition
  • labels (numpy.ndarray) – numerical labels for cell adjacency relationship
  • color (str) – single-character colours in a string, e.g. ‘rrrbgy’
  • style (str) – line style
  • centroid_style (str) – marker style of the cell centers
  • negative (any) – if None, do not plot edges corresponding to negative adjacency labels
  • linewidth (int) – line width
  • fallback_color (str) – colour for missing edges
  • verbose (bool) – print message about missing edges
  • axes (matplotlib.axes.Axes) – figure axes
Returns:

list of handles of the plotted edges,

handle of the plotted centroids

Return type:

tuple

tramway.plot.mesh.plot_delaunay(cells, labels=None, color=None, style='-', centroid_style='g+', negative=None, axes=None, linewidth=1, individual=False, fallback_color='gray')

Delaunay plot.

Parameters:
  • cells (Partition) – full partition
  • labels (numpy.ndarray) – numerical labels for cell adjacency relationship
  • color (str) – single-character colours in a string, e.g. ‘rrrbgy’
  • style (str) – line style
  • centroid_style (str) – marker style of the cell centers
  • negative (any) – if None, do not plot edges corresponding to negative adjacency labels; if ‘voronoi’, plot the corresponding Voronoi edge instead, for edges with negative labels
  • axes (matplotlib.axes.Axes) – figure axes
  • linewidth (int) – line width
  • individual (bool) – plot each edge independently; this generates a lot of handles and takes time
  • fallback_color (str) – colour for unexpected labels
Returns:

list of handles of the plotted edges,

handle of the plotted centroids

Return type:

tuple

tramway.plot.mesh.plot_distributed(cells, vertex_color='g', vertex_style='x', edge_color='r', arrow_size=5, arrow_color='y')

Plot a FiniteElements object as a mesh.

Parameters:
  • cells (tramway.inference.base.FiniteElements) – mesh prepared for the inference
  • vertex_color (str) – colour for the cell centers
  • vertex_style (str) – marker style for the cell centers
  • edge_color (str) – colour of the edge between adjacent cells
  • arrow_size (int) – size of the arrows along the edges
  • arrow_color (str) – colour of the arrows along the edges
Returns:

list of handles of the edges,

handle of the cell centers (vertices), list of handles of the arrow segments

Return type:

tuple

plot_distributed is similar to plot_delaunay but takes a FiniteElements object instead.

tramway.plot.mesh.plot_indices(*args, **kwargs)

Alias for plot_cell_indices().

plot_cell_indices was formerly named plot_indices.

tramway.plot.mesh.plot_cell_indices(cells, font_size=12, shift_indices=False, axes=None, **kwargs)

Plot cell indices at the cell centers.

Parameters:
  • cells (Partition or Tessellation or FiniteElements) – tessellation
  • font_size (int) – alias for fontsize
  • shift_indices (bool) – first cell is numbered 1 instead of 0
  • axes (matplotlib.axes.Axes) – figure axes; new in 0.6
Returns:

handles of the individual text elements

Return type:

list

Trailing keyword arguments are passed to text().

tramway.plot.map module

tramway.plot.map.cell_to_polygon(c, X, voronoi=None, bounding_box=None, region_point=None, return_voronoi=False)
tramway.plot.map.cell_to_polygon_(i, vertices, cell_vertices, Av, xlim=None, ylim=None, try_fix_corners=True)
tramway.plot.map.box_voronoi_2d(tessellation, xlim, ylim)
tramway.plot.map.scalar_map_2d(cells, values, aspect=None, clim=None, figure=None, axes=None, linewidth=1, delaunay=False, colorbar=True, alpha=None, colormap=None, unit=None, clabel=None, xlim=None, ylim=None, try_fix_corners=True, return_patches=False, **kwargs)

Plot a 2D scalar map as a colourful image.

Parameters:
  • cells (Partition or FiniteElements) – spatial description of the cells
  • values (pandas.DataFrame or numpy.ndarray) – feature value at each cell, that will be represented as a colour
  • aspect (str) – passed to set_aspect()
  • clim (2-element sequence) – passed to set_clim()
  • figure (matplotlib.figure.Figure) – figure handle
  • axes (matplotlib.axes.Axes) – axes handle
  • linewidth (int) – cell border line width
  • delaunay (bool or dict) – overlay the Delaunay graph; if dict, options are passed to plot_delaunay()
  • colorbar (bool or str or dict) – add a colour bar; if dict, options are passed to colorbar(); setting colorbar to ‘nice’ allows to produce a colorbar close to the figure of the same size as the figure
  • unit/clabel (str) – colorbar label, usually the unit of displayed feature
  • alpha (float) – alpha value of the cells
  • colormap (str) – colormap name; see also https://matplotlib.org/users/colormaps.html
  • xlim (2-element sequence) – lower and upper x-axis bounds
  • ylim (2-element sequence) – lower and upper y-axis bounds
  • return_patches (bool) – returns PatchCollection patches and the corresponding bin indices.

Extra keyword arguments are passed to PatchCollection().

tramway.plot.map.field_map_2d(cells, values, angular_width=30.0, overlay=False, aspect=None, figure=None, axes=None, cell_arrow_ratio=None, markercolor='y', markeredgecolor='k', markeralpha=0.8, markerlinewidth=None, transform=None, inferencemap=False, arrow_size=None, arrow_quantile_size=0.1, **kwargs)

Plot a 2D field (vector) map as arrows.

Parameters:
  • cells (Partition or FiniteElements) – spatial description of the cells
  • values (pandas.DataFrame or numpy.ndarray) – value at each cell, represented as a colour
  • angular_width (float) – angle of the tip of the arrows
  • overlay (bool) – do not plot the amplitude as a scalar map
  • aspect (str) – passed to set_aspect()
  • figure (matplotlib.figure.Figure) – figure handle
  • axes (matplotlib.axes.Axes) – axes handle
  • cell_arrow_ratio (float) – size of the largest arrow relative to the median inter-cell distance; default is 0.4 if inferencemap is True, else 1
  • markercolor (str) – colour of the arrows
  • markeredgecolor (str) – colour of the border of the arrows
  • markeralpha (float) – alpha value of the arrows
  • markerlinewidth (float) – line width of the border of the arrows
  • transform ('log', 'log10' or callable) – if overlay is False, transform applied to the amplitudes as a NumPy array; affects only the color-coded background map
  • inferencemap (bool) – if True, the arrow length only depends on the cell size
  • arrow_size (str) – new in 0.6; can be 'constant'
  • arrow_quantile_size (float) – new in 0.6; applies if arrow_size=='constant'; the base arrow size is set equal to a quantile of the inter-cell distance

Extra keyword arguments are passed to scalar_map_2d() if called.

If overlay is True, the marker-prefixed arguments can be renamed without the marker prefix. These arguments can only be keyworded.

tramway.plot.map.scalar_map_3d(cells, values, aspect=None, clim=None, figure=None, axes=None, colorbar=True, alpha=None, colormap=None, unit=None, clabel=None, xlim=None, ylim=None, zlim=None, triangulation_depth=2, **kwargs)

Plot a 2D scalar map as a colourful 3D surface.

Parameters:
  • cells (Tessellation or Partition) – spatial description of the cells
  • values (pandas.DataFrame, numpy.ndarray or Maps) – feature value at each cell, that will be represented as a colour
  • aspect (str) – passed to set_aspect()
  • clim (2-element sequence) – passed to set_clim(); note clim affects colour, not height.
  • figure (matplotlib.figure.Figure) – figure handle
  • axes (matplotlib.axes.Axes) – axes handle
  • colorbar (bool or str or dict) – add a colour bar; if dict, options are passed to colorbar(); setting colorbar to ‘nice’ allows to produce a colorbar close to the figure of the same size as the figure
  • unit/clabel (str) – colorbar label, usually the unit of displayed feature
  • alpha (float) – alpha value of the cells
  • colormap (str) – colormap name; see also https://matplotlib.org/users/colormaps.html
  • xlim (2-element sequence) – lower and upper x-axis bounds
  • ylim (2-element sequence) – lower and upper y-axis bounds
  • zlim (2-element sequence) – lower and upper z-axis bounds; note zlim affects height, not colour.

Extra keyword arguments are passed to PatchCollection().

tramway.plot.contour module

class tramway.plot.contour.ContourEditor(figure, renderer=None)

Bases: object

area
axes
cell
cell_adjacency
cell_centers
cell_count
cells
curl(F, dr, A)
delaunay
dilation_adjacency
draw()
field(cs)
find_cell(pt)
integral(contour, inner)
map
refresh()
step
sum(x, *args)
surface_area(contour, inner)
tangent(cs)
variable
variables

tramway.plot.tk.contour module

class tramway.plot.tk.contour.ContourEditingApp(parent=None)

Bases: tkinter.Frame

create_widgets()
debug
disable_widgets()
enable_widgets()
new_file(*args, **kwargs)
set_maps(maps)
class tramway.plot.tk.contour.FileChooser(parent, filetypes={}, **kwargs)

Bases: tkinter.Frame

open_input_file()
class tramway.plot.tk.contour.TkContourEditor(parent, **kwargs)

Bases: matplotlib.backends.backend_tkagg.FigureCanvasTkAgg

cells
debug
map
onclick(event)
toggle_delaunay(*args)
variables
tramway.plot.tk.contour.contour_utility()

tramway.plot.bokeh subpackage

tramway.plot.bokeh.map module

tramway.plot.bokeh.map.plot_points(cells, style='circle', size=2, color=None, figure=None, **kwargs)

Plot molecule locations.

If no colour is explicitly defined, colouring is based on the cell index.

Parameters:
  • cells (Partition) – full partition
  • style (str) – point marker style
  • size (float) – point marker size (in screen units)
  • color (str or numpy.ndarray) – cell colours
  • figure (bokeh.plotting.figure.Figure) – figure handle
Returns:

handles of the various clouds of points

Return type:

list

tramway.plot.bokeh.map.plot_trajectories(trajs, color=None, loc_style='circle', figure=None, **kwargs)

Plot trajectories.

If no colour is explicitly defined, colouring is based on the trajectory index.

Parameters:
  • trajs (pandas.DataFrame) – full partition
  • loc_style (str) – location marker style
  • loc_size (float) – location marker size (in screen units)
  • color (str or numpy.ndarray) – trajectory colours
  • figure (bokeh.plotting.figure.Figure) – figure handle
Returns:

handles of the glyphs

Return type:

list

tramway.plot.bokeh.map.plot_delaunay(cells, labels=None, color=None, style='-', figure=None, linewidth=1, **kwargs)

Delaunay plot.

Parameters:
  • cells (Partition) – full partition
  • labels (numpy.ndarray) – numerical labels for cell adjacency relationship
  • color (str) – single-character colours in a string, e.g. ‘rrrbgy’
  • style (str) – line style
  • figure (bokeh.plotting.figure.Figure) – figure handle
  • linewidth (int) – line width
Returns:

list of handles of the plotted edges,

handle of the plotted centroids

Return type:

tuple

tramway.plot.bokeh.map.scalar_map_2d(cells, values, clim=None, figure=None, delaunay=False, colorbar=True, colormap=None, unit=None, clabel=None, colorbar_figure=None, xlim=None, ylim=None, try_fix_corners=True, **kwargs)

Plot an interactive 2D scalar map as a colourful image.

Parameters:
  • cells (Partition) – spatial description of the cells
  • values (pandas.Series or pandas.DataFrame) – feature value at each cell/bin, encoded into a colour
  • clim (2-element sequence) – passed to set_clim()
  • figure (bokeh.plotting.figure.Figure) – figure handle
  • delaunay (bool or dict) – overlay the Delaunay graph; if dict, options are passed to plot_delaunay()
  • colorbar (bool or str or dict) – add a colour bar; if dict, options are passed to ColorBar()
  • unit/clabel (str) – colorbar label, usually the unit of displayed feature
  • colormap (str) – colormap name; see also https://matplotlib.org/users/colormaps.html
  • xlim (2-element sequence) – lower and upper x-axis bounds
  • ylim (2-element sequence) – lower and upper y-axis bounds
tramway.plot.bokeh.map.field_map_2d(cells, values, angular_width=30.0, figure=None, cell_arrow_ratio=None, markercolor='#bfbf00', markeredgecolor='#000000', markeralpha=0.8, markerlinewidth=None, inferencemap=False, **kwargs)

Plot a 2D field (vector) map as arrows.

Parameters:
  • cells (Partition or Distributed) – spatial description of the cells
  • values (pandas.DataFrame or numpy.ndarray) – value at each cell, represented as a colour
  • angular_width (float) – angle of the tip of the arrows
  • figure (matplotlib.figure.Figure) – figure handle
  • cell_arrow_ratio (float) – size of the largest arrow relative to the median inter-cell distance; default is 0.4 if inferencemap is True, else 1
  • markercolor (str) – colour of the arrows
  • markeredgecolor (str) – colour of the border of the arrows
  • markeralpha (float) – alpha value of the arrows
  • markerlinewidth (float) – line width of the border of the arrows
  • inferencemap (bool) – if True, the arrow length only depends on the cell size
tramway.plot.bokeh.map.add_colorbar(figure, colormap=None, low=0, high=1, unit=None, clabel=None, colorbar_figure=None)

tramway.plot.animation subpackage

This package is no longer maintained and is superseded by the mpl functionalities of RWAnalyzer.

See for example to_color_movie(), animate() and animate().

class tramway.plot.animation.VideoReader(*args, **kwargs)

Bases: object

class tramway.plot.animation.VideoWriter(frame_rate, bit_rate=None, dots_per_inch=200, figure=None, axes=None, axis=True, verbose=True, **kwargs)

Bases: object

grab_frame(*args, **kwargs)
range(N)
saving(output_file)
class tramway.plot.animation.VideoWriterReader(filepath, *args, **kwargs)

Bases: object

axes
figure
fps
grab_frame(*args, **kwargs)
play(fps=None, **kwargs)
range(N)
saving()
verbose
exception tramway.plot.animation.Aborted

Bases: Exception

tramway.plot.animation.xyt module

tramway.plot.animation.xyt.animate_trajectories_2d(xyt, output_file=None, frame_rate=None, bit_rate=None, dots_per_inch=200, play=False, time_step=None, time_unit='s', color=None, line_width=1, marker_style='o', marker_size=4, figure=None, axes=None, bounding_box=None, axis=True, verbose=True, time_precision=2, **kwargs)

Animate 2D trajectories.

Parameters:
  • xyt (pandas.DataFrame) – nxyt data.
  • output_file (str) – path to .mp4 file.
  • frame_rate (float) – number of frames per second.
  • bit_rate (int) – movie bitrate; see also FFMpegWriter.
  • dots_per_inch (int) – dpi argument passed to saving().
  • play (bool) – play the movie once generated.
  • time_step (float) – time step between successive frames.
  • time_unit (str) – time unit for time display; if None, no title is displayed.
  • color (list or numpy.ndarray or callable) – trajectory colour.
  • line_width (float) – translocation line width.
  • marker_style (str) – location marker style.
  • marker_size (float) – location marker size.
  • figure (matplotlib.figure.Figure) – figure handle.
  • axes (matplotlib.axes.Axes) – axes handle.
  • bounding_box (matplotlib.transforms.Bbox) – axis bounding box.
  • axis (bool or str) – make the axes visible.
  • verbose (bool) – ask for confirmation if the output file is to be overwritten and draw a progress bar (module tqdm must be available).
  • time_precision (int) – number of decimals for time display.

Extra keyword arguments are passed to FFMpegWriter.

tramway.plot.animation.map module

tramway.plot.animation.map.animate_map_2d(_map, cells, output_file=None, frame_rate=1, bit_rate=None, dots_per_inch=200, play=False, time_step=None, time_unit='s', figure=None, axes=None, bounding_box=None, colormap=None, colorbar=True, axis=True, verbose=True, time_precision=2, **kwargs)

Animate 2D maps.

Parameters:
  • _map (pandas.DataFrame) – scalar or vector map.
  • cells (tramway.tessellation.base.Partition) – spatial-temporal binning.
  • output_file (str) – path to .mp4 file.
  • frame_rate (float) – number of frames per second.
  • bit_rate (int) – movie bitrate; see also FFMpegWriter.
  • dots_per_inch (int) – dpi argument passed to saving().
  • play (bool) – play the movie once generated.
  • time_step (float) – time step between successive frames.
  • time_unit (str) – time unit for time display; if None, no title is displayed.
  • figure (matplotlib.figure.Figure) – figure handle.
  • axes (matplotlib.axes.Axes) – axes handle.
  • bounding_box (matplotlib.transforms.Bbox) – axis bounding box.
  • colormap (str) – colormap name; see also https://matplotlib.org/users/colormaps.html.
  • colorbar (bool or str or dict) – see also scalar_map_2d().
  • axis (bool or str) – make the axes visible.
  • verbose (bool) – ask for confirmation if the output file is to be overwritten and draw a progress bar (module tqdm must be available).
  • time_precision (int) – number of decimals for time display.

Extra keyword arguments are passed to FFMpegWriter.