morphoclass.vis module

Functions for visualizing data.

morphoclass.vis.get_color_map(labels: Sequence[str])dict[str, tuple[int, int, int]]

Map labels to colors in the default color palette.

In matplotlib, what is the sequence of colors that will be used when multiple plots are created? This function gives access to this sequence in form of a map “given label” -> “color”.

Parameters

labels – A sequence of arbitrary labels.

Returns

A map from the input labels to colors. The colors are represented by triples of floats between 0 and 1.

Return type

dict

morphoclass.vis.plot_acc_cv(values, label=None, ax=None, title=None)

Plot cross-validated accuracy scores.

Parameters
  • values (np.ndarray) – Accuracy values to be plotted. The array should be of shape (n_splits, n_epochs).

  • label (str, optional) – The label which should appear on the legend, provided that the ax object hast the legend enabled.

  • ax (matplotlib.axes.Axes, optional) – Matplotlib Axes object to plot onto.

  • title (str, optional) – The title to be displayed above the axes.

morphoclass.vis.plot_accuracies(acc, val_acc, color_train='blue', color_val='red', title=None, file_name=None, supported_ext=None)

Plot the learning curves for the train and validation sets.

Parameters
  • acc (list, numpy.ndarray) – Train accuracy.

  • val_acc (list, numpy.ndarray) – Validation accuracy.

  • color_train (str, default "blue") – Colour for the training curves.

  • color_val (str, default "red") – Colour for the validation curves.

  • title (str, optional) – Title of the plot.

  • file_name (str, pathlib.Path, optional) – Path to where to store the plot.

  • supported_ext (list, optional) – Supported image extensions. If default, it will save as “.png”, “.eps”, “.pdf”.

Returns

Figure of the plot.

Return type

matplotlib.figure.Figure

morphoclass.vis.plot_barcode_enhanced(ph, ax, valID=2, linewidth=1.2)

Plot colored barcode.

Parameters
  • ph (np.ndarray) – Persistence diagram.

  • ax (matplotlib.axes.Axes) – Axis for the plot.

  • valID (int, optional) – [description], by default 2

  • linewidth (float, optional) – Line width, by default 1.2

Returns

  • CS3 (ScalarMappable) – Colors for colorbar.

  • colors (list_like) – List of bar colors.

morphoclass.vis.plot_confusion_matrix(cm, file_name, labels, supported_ext=None)

Confusion matrix.

Parameters
  • cm (np.ndarray) – The confusion matrix values.

  • file_name (str, pathlib.Path) – File name where to save the CM plot.

  • labels (list) – List of labels for prediction.

morphoclass.vis.plot_counts_per_layer(mtypes: pd.Series, figsize: tuple[float, float] = (10, 6))Figure

Make a bar plot with the count of samples per cortical layer.

Parameters
  • mtypes – A pandas series with the m-type labels of all samples. The labels are expected to contain the layer information in the form of the prefix LXX_ or XX_ where XX are an arbitrary number of digits.

  • figsize – The size of the figure

Returns

The plot figure.

Return type

Figure

morphoclass.vis.plot_counts_per_subclass(mtypes: pd.Series, figsize: tuple[float, float] = (10, 6))Figure

Make a bar plot with the count of samples per m-type.

The m-type labels should contain the layer prefix so that the bars in the plot can be grouped by layer.

Parameters
  • mtypes – A pandas series with the m-type labels of all samples. The labels are expected to contain the layer information in the form of the prefix LXX_ or XX_ where XX are an arbitrary number of digits.

  • figsize – The size of the figure

Returns

The plot figure.

Return type

Figure

morphoclass.vis.plot_diagram_enhanced(ph, ax, alpha=1.0, valID=2, edgecolors='black', s=30)

Plot colored diagram.

Parameters
  • ph (np.ndarray) – Persistence diagram.

  • ax (matplotlib.axes.Axes) – Axis for the plot.

  • alpha (float, optional) – Transperancey of plot, by default 1.0.

  • valID (int, optional) – [description], by default 2

  • edgecolors (float) – Transperancey of plotby default black.

  • s (float, optional) – Size of soma, by default 30.

Returns

  • CS3 (ScalarMappable) – Colors for colorbar.

  • colors (list_like) – List of bar colors.

morphoclass.vis.plot_histogram(title: str, data: Sequence[float], figsize: tuple[float, float] = (6, 4))Figure

Make a histogram plot.

Parameters
  • title – The figure title.

  • data – The data to plot.

  • figsize – The size of the figure.

Returns

Return type

The figure with the histogram.

morphoclass.vis.plot_histogram_panel(title: str, labeled_data: dict[str, Sequence[float]], figsize: tuple[float, float] = (12, 4))Figure

Make a panel of histogram plots for each labeled data sequence.

Parameters
  • title – The figure title.

  • labeled_data – Map of some labels to the corresponding data. The data is a sequence of floats.

  • figsize – The figure size.

Returns

The plot.

Return type

Figure

morphoclass.vis.plot_learning_acc(history, title=None, file_name=None)

Plot training/validation accuracies.

Parameters
  • history (dict) – Dictionary with keys ‘train_acc’ and ‘val_acc’ and the corresponding values list_like objects with accuracy values.

  • title (str, optional) – The title for the plot. If None then the default title “Learning Curves” will be used.

  • file_name (str) – Path to where to save the plot.

morphoclass.vis.plot_learning_curves(acc, loss, val_acc, val_loss, color_acc='green', color_loss='orange', title=None, file_name=None)

Plot the learning curves for the train and validation sets.

Parameters
  • acc (list, numpy.ndarray) – Train accuracy.

  • loss (list, numpy.ndarray) – Train loss.

  • val_acc (list, numpy.ndarray) – Validation accuracy.

  • val_loss (list, numpy.ndarray) – Validation loss.

  • color_acc (str) – Colour for the accuracy curves.

  • color_loss (str) – Colour for the loss curves.

  • title (str) – Title of the plot.

  • file_name (str, pathlib.Path) – Path to where to store the plot.

Returns

Figure of the plot.

Return type

matplotlib.figure.Figure

morphoclass.vis.plot_mean_ci(ax, values, label=None, color=None, weight=1, zorder=None, show_ci=True)

Plot a cross-validation learning curve.

the values of the evaluation metric should be stored in the array values with the dimension (n_splits, n_epochs)

Parameters
  • ax – A matplotlib axis object.

  • values – The metric evaluation values.

  • label – The label of the curve.

  • color – The color of the curve.

  • weight – Determines the thickness of lines and transparency.

  • zorder – Z-order of the curve to be plotted.

  • show_ci (bool) – Whether to show the CIs.

Returns

The color of the plotted curves.

Return type

color

morphoclass.vis.plot_morphology_images(neuron: tmd.Neuron.Neuron, neuron_label: str, neuron_name: str, figsize: tuple[float, float] = (12, 4))matplotlib.figure.Figure

Plot morphology images.

Parameters
  • neuron – A neuron morphology.

  • neuron_label – Morphology type.

  • neuron_name – Morphology name.

  • figsize – The size of the figure.

Returns

fig – The plot figure.

Return type

matplotlib.figure.Figure

morphoclass.vis.plot_neurite(neurite: tmd.Tree.Tree.Tree, ax: matplotlib.axes._axes.Axes, *, rotation: int = 0, soma_size: int = 1, edge_width: int = 1)None

Plot a neurite.

Parameters
  • neurite – The neurite.

  • ax – Matplotlib axes.

  • rotation – The rotation around the y-axis (normally the vertical axis) in degrees.

  • soma_size – The size of the soma in the plot. It will be plotted in red.

  • edge_width – The width of the edges in the plot. They will be plotted in black.

morphoclass.vis.plot_number_of_nodes(k, neurite_and_nodes, rtype, imagedir, figsize=(6, 4), supported_ext=None)

Plot number of nodes in the graph.

Parameters
  • k (str) – The neurite type: “axon”, “basal”, ‘apical’, “neurites”.

  • neurite_and_nodes (dict) – Dictionary with neurite types as keys, and graph/PD nodes as values.

  • rtype (str) – Can have 2 values:0 ‘graph’ or ‘PD’.

  • imagedir (pathlib.Path) – The path where to store the generated plot.

  • figsize (tuple, default (6, 4)) – The figsize for the matplotlib figure.

  • supported_ext (list, optional) – The extensions to store the images. By default it will store them as “.png”, “.eps”, “.pdf”.

Returns

Path where the image is stored.

Return type

pathlib.Path

morphoclass.vis.plot_number_of_nodes_per_layer(k, layer_neurite_and_nodes, rtype, imagedir, figsize=(12, 4), supported_ext=None)

Plot number of nodes in the graph per layer.

Parameters
  • k (str) – The neurite type: “axon”, “basal”, ‘apical’, “neurites”.

  • layer_neurite_and_nodes – Nested dictionary with neurite types as first-level keys, layers as second-level keys, and graph/PD nodes as values.

  • rtype (str) – Can have 2 values:0 ‘graph’ or ‘PD’.

  • imagedir (pathlib.Path) – The path where to store the generated plot.

  • figsize (tuple, default (12, 4)) – The figsize for the matplotlib figure.

  • supported_ext (list, optional) – The extensions to store the images. By default it will store them as “.png”, “.eps”, “.pdf”.

Returns

Path where the image is stored.

Return type

pathlib.Path

morphoclass.vis.plot_persistence_diagram(persistence_data: list[list[int]], ax: matplotlib.axes.Axes, size: int = 1)None

Plot a persistence diagram.

Parameters
  • persistence_data – The persistence data: a sequence of pairs (x, y), the points of the persistence diagram.

  • ax – Matplotlib axes.

  • size – The size of the persistence points in the plot.

morphoclass.vis.plot_persistence_image(persistence_data: list[list[int]], ax: matplotlib.axes.Axes)None

Plot a persistence diagram.

Parameters
  • persistence_data – The persistence data: a sequence of pairs (x, y), the points of the persistence diagram.

  • ax – Matplotlib axes.

morphoclass.vis.plot_tree(tree, ax, rot=0, scale=1.0, edge_color='green', node_size=0.0, width=1, center_nodes=True, show_axes=False)

Plot a tmd tree class as a 2D projection.

Parameters
  • tree – Tree data in form of a tmd.Tree class.

  • ax – Pyplot axes object.

  • rot – Rotation angle around the vertical axis in degrees.

  • scale – Overall scale of the plot.

  • edge_color – Color of the tree edges.

  • node_size – Size of the tree nodes.

  • width – Width of the tree branches.

  • center_nodes (boo, optional) – Move all nodes so that the first node is at the origin.

  • show_axes (bool, optional) – Show / hide plot axes.