neurom.view.common

Functionality for styling plots.

Functions

dict_if_none

Return an empty dict if arg is None.

figure_naming

Returns a formatted string with the figure name and title.

generate_cylindrical_points

Generate a 3d mesh of a cylinder with start and end points, and varying radius.

get_figure

Function to be used for viewing - plotting, to initialize the matplotlib figure - axes.

plot_cylinder

Plot a 3d cylinder.

plot_labels

Sets the labels options of a matplotlib plot.

plot_legend

Function that defines the legend options of a matplotlib plot.

plot_sphere

Plots a 3d sphere, given the center and the radius.

plot_style

Set the basic options of a matplotlib figure, to be used by viewing - plotting functions.

plot_ticks

Function that defines the labels options of a matplotlib plot.

plot_title

Set title options of a matplotlib plot.

project_cylinder_onto_2d

Take cylinder defined by start/end, and project it onto the plane.

save_plot

Generates a figure file in the selected directory.

update_plot_limits

Sets the limit options of a matplotlib plot.

neurom.view.common.dict_if_none(arg)[source]

Return an empty dict if arg is None.

neurom.view.common.figure_naming(pretitle='', posttitle='', prefile='', postfile='')[source]

Returns a formatted string with the figure name and title.

Helper function to define the strings that handle pre-post conventions for viewing - plotting title and saving options.

Parameters
  • pretitle (str) – String to include before the general title of the figure.

  • posttitle (str) – String to include after the general title of the figure.

  • prefile (str) – String to include before the general filename of the figure.

  • postfile (str) – String to include after the general filename of the figure.

Returns

String to include in the figure name and title, in a suitable form.

Return type

str

neurom.view.common.generate_cylindrical_points(start, end, start_radius, end_radius, linspace_count=300)[source]

Generate a 3d mesh of a cylinder with start and end points, and varying radius.

Based on: http://stackoverflow.com/a/32383775

neurom.view.common.get_figure(new_fig=True, subplot='111', params=None)[source]

Function to be used for viewing - plotting, to initialize the matplotlib figure - axes.

Parameters
  • new_fig (bool) – Defines if a new figure will be created, if false current figure is used

  • subplot (tuple or matplolib subplot specifier string) – Create axes with these parameters

  • params (dict) – extra options passed to add_subplot()

Returns

Matplotlib Figure and Axes

neurom.view.common.plot_cylinder(ax, start, end, start_radius, end_radius, color='black', alpha=1.0, linspace_count=300)[source]

Plot a 3d cylinder.

neurom.view.common.plot_labels(ax, label_fontsize=14, xlabel=None, xlabel_arg=None, ylabel=None, ylabel_arg=None, zlabel=None, zlabel_arg=None)[source]

Sets the labels options of a matplotlib plot.

Parameters
  • ax – matplotlib axes

  • label_fontsize (int) – Size of the labels’ font

  • xlabel (str) – The xlabel for the figure

  • xlabel_arg (dict) – Passsed into matplotlib as xlabel arguments

  • ylabel (str) – The ylabel for the figure

  • ylabel_arg (dict) – Passsed into matplotlib as ylabel arguments

  • zlabel (str) – The zlabel for the figure

  • zlabel_arg (dict) – Passsed into matplotlib as zlabel arguments

neurom.view.common.plot_legend(ax, no_legend=True, legend_arg=None)[source]

Function that defines the legend options of a matplotlib plot.

Parameters
  • ax – matplotlib axes

  • no_legend (bool) – Defines the presence of a legend in the figure

  • legend_arg (dict) – Addition arguments for matplotlib.legend() call

neurom.view.common.plot_sphere(ax, center, radius, color='black', alpha=1.0, linspace_count=300)[source]

Plots a 3d sphere, given the center and the radius.

neurom.view.common.plot_style(fig, ax, pretitle='', title='Figure', posttitle='', title_fontsize=14, title_arg=None, label_fontsize=14, xlabel=None, xlabel_arg=None, ylabel=None, ylabel_arg=None, zlabel=None, zlabel_arg=None, tick_fontsize=12, xticks=None, xticks_args=None, yticks=None, yticks_args=None, zticks=None, zticks_args=None, white_space=30, no_legend=True, legend_arg=None, no_axes=False, aspect_ratio='equal', tight=False, **_)[source]

Set the basic options of a matplotlib figure, to be used by viewing - plotting functions.

Parameters
  • fig (matplotlib figure) – figure

  • ax (matplotlib axes, belonging to fig) – axes

  • pretitle (str) – String to include before the general title of the figure

  • posttitle (str) – String to include after the general title of the figure

  • title (str) – Set the title for the figure

  • title_fontsize (int) – Defines the size of the title’s font

  • title_arg (dict) – Addition arguments for matplotlib.title() call

  • label_fontsize (int) – Size of the labels’ font

  • xlabel (str) – The xlabel for the figure

  • xlabel_arg (dict) – Passsed into matplotlib as xlabel arguments

  • ylabel (str) – The ylabel for the figure

  • ylabel_arg (dict) – Passsed into matplotlib as ylabel arguments

  • zlabel (str) – The zlabel for the figure

  • zlabel_arg (dict) – Passsed into matplotlib as zlabel arguments

  • tick_fontsize (int) – Defines the size of the ticks’ font

  • xticks ([list of ticks]) – Defines the values of x ticks in the figure

  • xticks_args (dict) – Passsed into matplotlib as xticks arguments

  • yticks ([list of ticks]) – Defines the values of y ticks in the figure

  • yticks_args (dict) – Passsed into matplotlib as yticks arguments

  • zticks ([list of ticks]) – Defines the values of z ticks in the figure

  • zticks_args (dict) – Passsed into matplotlib as zticks arguments

  • white_space (float) – whitespace added to surround the tight limit of the data

  • no_legend (bool) – Defines the presence of a legend in the figure

  • legend_arg (dict) – Addition arguments for matplotlib.legend() call

  • no_axes (bool) – If True the labels and the frame will be set off

  • aspect_ratio (str) – Sets aspect ratio of the figure, according to matplotlib aspect_ratio

  • tight (bool) – If True the tight layout of matplotlib will be activated

Returns

Matplotlib figure, matplotlib axes

neurom.view.common.plot_ticks(ax, tick_fontsize=12, xticks=None, xticks_args=None, yticks=None, yticks_args=None, zticks=None, zticks_args=None)[source]

Function that defines the labels options of a matplotlib plot.

Parameters
  • ax – matplotlib axes

  • tick_fontsize (int) – Defines the size of the ticks’ font

  • xticks ([list of ticks]) – Defines the values of x ticks in the figure

  • xticks_args (dict) – Passsed into matplotlib as xticks arguments

  • yticks ([list of ticks]) – Defines the values of y ticks in the figure

  • yticks_args (dict) – Passsed into matplotlib as yticks arguments

  • zticks ([list of ticks]) – Defines the values of z ticks in the figure

  • zticks_args (dict) – Passsed into matplotlib as zticks arguments

neurom.view.common.plot_title(ax, pretitle='', title='Figure', posttitle='', title_fontsize=14, title_arg=None)[source]

Set title options of a matplotlib plot.

Parameters
  • ax – matplotlib axes

  • pretitle (str) – String to include before the general title of the figure

  • posttitle (str) – String to include after the general title of the figure

  • title (str) – Set the title for the figure

  • title_fontsize (int) – Defines the size of the title’s font

  • title_arg (dict) – Addition arguments for matplotlib.title() call

neurom.view.common.project_cylinder_onto_2d(ax, plane, start, end, start_radius, end_radius, color='black', alpha=1.0)[source]

Take cylinder defined by start/end, and project it onto the plane.

Parameters
  • ax – matplotlib axes

  • plane (tuple of int) – where x, y, z = 0, 1, 2, so (0, 1) is the xy axis

  • start (np.array) – start coordinates

  • end (np.array) – end coordinates

  • start_radius (float) – start radius

  • end_radius (float) – end radius

  • color – matplotlib color

  • alpha (float) – alpha value

Note: There are probably more efficient ways of doing this: here the 3d outline is calculated, the non-used plane coordinates are dropped, a tight convex hull is found, and that is used for a filled polygon

neurom.view.common.save_plot(fig, prefile='', postfile='', output_path='./', output_name='Figure', output_format='png', dpi=300, transparent=False, **_)[source]

Generates a figure file in the selected directory.

Parameters
  • fig – matplotlib figure

  • prefile (str) – Include before the general filename of the figure

  • postfile (str) – Included after the general filename of the figure

  • output_path (str) – Define the path to the output directory

  • output_name (str) – String to define the name of the output figure

  • output_format (str) – String to define the format of the output figure

  • dpi (int) – Define the DPI (Dots per Inch) of the figure

  • transparent (bool) – If True the saved figure will have a transparent background

neurom.view.common.update_plot_limits(ax, white_space)[source]

Sets the limit options of a matplotlib plot.

Parameters
  • ax – matplotlib axes

  • white_space (float) – whitespace added to surround the tight limit of the data

Note: This relies on ax.dataLim (in 2d) and ax.[xy, zz]_dataLim being set in 3d