5.1. Draw

The draw functions are helper functions to plot reeb graphs and merge trees.

cereeberus.draw.draw.dict_to_list(d)[source]
cereeberus.draw.draw.line_loop_index(R)[source]

Determine if edges between two nodes should be lines or loops

Parameters:

R (Reeb Graph) – Reeb Graph

Returns:

2-element tuple containing

  • line_index (list) : list of indices for edges to be drawn as lines

  • loop_index (list) : list of indices for edges to be drawn as loops

cereeberus.draw.draw.slope_intercept(pt0, pt1)[source]

Compute slope and intercept to be used in the bezier curve function

Parameters:
  • pt0 (ordered pair) – first point

  • pt1 (ordered pair) – second point

Returns:

2-element tuple containing

  • m (float) : slope

  • b (float) : intercept

cereeberus.draw.draw.bezier_curve(pt0, midpt, pt1)[source]

Compute bezier curves for plotting two edges between a single set of nodes

Parameters:
  • pt0 (ordered pair) – first point

  • midpt (ordered pair) – midpoint for bezier curve to pass through

  • pt1 (ordered pair) – second point

Returns:

array of points to be used in plotting

Return type:

points (np array)

cereeberus.draw.draw.reeb_plot(R, with_labels=True, with_colorbar=False, cpx=0.1, cpy=0.1, ax=None, **kwargs)[source]

Main plotting function for the Reeb Graph Class

Parameters:
  • R (Reeb Graph) – object of Reeb Graph class

  • with_labels (bool) – parameter to control whether or not to plot labels

  • with_colorbar (bool) – parameter to control whether or not to plot colorbar

  • cp (float) – parameter to control curvature of loops in the plotting function. For vertical Reeb graph, only mess with cpx.

cereeberus.draw.draw.node_label_counts(R, labels, categories=None)[source]

Count, per vertex, how many of its assigned data points fall into each category of labels.

Requires R to have been built with cereeberus.computeMapper(), which records a node_points attribute on the graph mapping each vertex to the list of original point indices assigned to it.

Parameters:
  • R (MapperGraph) – a mapper graph built via computeMapper.

  • labels (sequence) – a category label for every point in the point cloud (or distance matrix) that was used to build R. Indexed the same way as that point cloud (or, if pointcloud was None, the same way as the rows/columns of the distance_matrix you built the graph with).

  • categories (list, optional) – the ordered list of category values to report counts for. Defaults to sorted(set(labels)).

Returns:

node -> {category: count}

Return type:

dict

cereeberus.draw.draw.pie_plot(R, labels, categories=None, colors=None, zoom=0.15, size_by_points=False, min_zoom=0.08, max_zoom=0.3, with_edges=True, with_legend=True, with_labels=True, cpx=0.1, cpy=0.1, ax=None)[source]

Plot a mapper graph with each vertex drawn as a small pie-chart picture showing the percentage breakdown of labels among the original data points assigned to that vertex.

Requires R to have been built with cereeberus.computeMapper() (which records per-node point membership); see node_label_counts.

Parameters:
  • R (MapperGraph) – a mapper graph built via computeMapper.

  • labels (sequence) – a category label for every point in the point cloud (or distance matrix) used to build R.

  • categories (list, optional) – ordered category values to plot. Defaults to sorted(set(labels)).

  • colors (dict, optional) – mapping from category value to a matplotlib color. Defaults to the “tab10” colormap.

  • zoom (float) – size of each pie-chart glyph, as a fraction of its rendered base size. The right value depends on how tightly packed your graph’s node positions are: dense graphs need a smaller zoom to avoid neighboring pies overlapping (which can create odd-looking visual artifacts where circles overlap). Start around 0.1-0.2 and adjust to taste.

  • size_by_points (bool) – if True, scale each pie’s size by the number of points assigned to that node. This can be useful for emphasizing nodes that represent more data, but can also make the graph harder to read if the size differences are extreme. If True, min_zoom and max_zoom control the range of zoom values.

  • min_zoom (float) – when size_by_points is True, the minimum and maximum zoom values to use for the smallest and largest nodes, respectively.

  • max_zoom (float) – when size_by_points is True, the minimum and maximum zoom values to use for the smallest and largest nodes, respectively.

  • with_edges (bool) – whether to draw the underlying graph edges.

  • with_legend (bool) – whether to add a legend mapping colors to category values.

  • with_labels (bool) – whether to draw each node’s index/name as a text label on top of its pie glyph, matching reeb_plot.

  • cpx (float) – curvature parameters for multi-edges, as in reeb_plot.

  • cpy (float) – curvature parameters for multi-edges, as in reeb_plot.

  • ax (matplotlib.axes.Axes, optional)

Returns:

matplotlib.axes.Axes