neurom.view.matplotlib_utils¶
Functionality for styling plots.
Functions
|
Return an empty dict if arg is None. |
|
Returns a formatted string with the figure name and title. |
|
Generate a 3d mesh of a cylinder with start and end points, and varying radius. |
|
Function to be used for viewing - plotting, to initialize the matplotlib figure - axes. |
|
Plot a 3d cylinder. |
|
Sets the labels options of a matplotlib plot. |
|
Function that defines the legend options of a matplotlib plot. |
|
Plots a 3d sphere, given the center and the radius. |
|
Set the basic options of a matplotlib figure, to be used by viewing - plotting functions. |
|
Function that defines the labels options of a matplotlib plot. |
|
Set title options of a matplotlib plot. |
|
Take cylinder defined by start/end, and project it onto the plane. |
|
Generates a figure file in the selected directory. |
|
Sets the limit options of a matplotlib plot. |
- neurom.view.matplotlib_utils.dict_if_none(arg)¶
Return an empty dict if arg is None.
- neurom.view.matplotlib_utils.figure_naming(pretitle='', posttitle='', prefile='', postfile='')¶
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.matplotlib_utils.generate_cylindrical_points(start, end, start_radius, end_radius, linspace_count=300)¶
Generate a 3d mesh of a cylinder with start and end points, and varying radius.
Based on: http://stackoverflow.com/a/32383775
- neurom.view.matplotlib_utils.get_figure(new_fig=True, subplot=(1, 1, 1), params=None)¶
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) – Create axes with these parameters
params (dict) – extra options passed to add_subplot()
- Returns:
Matplotlib Figure and Axes
- neurom.view.matplotlib_utils.plot_cylinder(ax, start, end, start_radius, end_radius, color='black', alpha=1.0, linspace_count=300)¶
Plot a 3d cylinder.
- neurom.view.matplotlib_utils.plot_labels(ax, label_fontsize=14, xlabel=None, xlabel_arg=None, ylabel=None, ylabel_arg=None, zlabel=None, zlabel_arg=None)¶
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.matplotlib_utils.plot_legend(ax, no_legend=True, legend_arg=None)¶
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.matplotlib_utils.plot_sphere(ax, center, radius, color='black', alpha=1.0, linspace_count=300)¶
Plots a 3d sphere, given the center and the radius.
- neurom.view.matplotlib_utils.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, **_)¶
Set the basic options of a matplotlib figure, to be used by viewing - plotting functions.
- Parameters:
fig – matplotlib 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 – Defines the values of x ticks in the figure (1D array-like)
xticks_args (dict) – Passsed into matplotlib as xticks arguments
yticks – Defines the values of y ticks in the figure( 1D array-like)
yticks_args (dict) – Passsed into matplotlib as yticks arguments
zticks – Defines the values of z ticks in the figure (1D array-like)
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.matplotlib_utils.plot_ticks(ax, tick_fontsize=12, xticks=None, xticks_args=None, yticks=None, yticks_args=None, zticks=None, zticks_args=None)¶
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 – Defines the values of x ticks in the figure (1D array-like)
xticks_args (dict) – Passsed into matplotlib as xticks arguments
yticks – Defines the values of y ticks in the figure (1D array-like)
yticks_args (dict) – Passsed into matplotlib as yticks arguments
zticks – Defines the values of z ticks in the figure (1D array-like)
zticks_args (dict) – Passsed into matplotlib as zticks arguments
- neurom.view.matplotlib_utils.plot_title(ax, pretitle='', title='Figure', posttitle='', title_fontsize=14, title_arg=None)¶
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.matplotlib_utils.project_cylinder_onto_2d(ax, plane, start, end, start_radius, end_radius, color='black', alpha=1.0)¶
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 (list of float) – start coordinates
end (list of float) – 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.matplotlib_utils.save_plot(fig, prefile='', postfile='', output_path='./', output_name='Figure', output_format='png', dpi=300, transparent=False, **_)¶
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.matplotlib_utils.update_plot_limits(ax, white_space)¶
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