Plotting utilities
- pyballmapper.plotting.generate_partitions(node_contents, original_element_values)
Given collections X_i of sets Y_ij and a function U Y_ij -> Z, computes for each i the count of elements in X_i that map to a given value in Z.
- node_contents:
dict of lists such that node_contents[node] is a list of all elements contained in node.
- original_element_values:
dict of values associated to each of the original set of elements. Not necessarily numeric.
- class pyballmapper.plotting.graph_GUI(graph, my_palette, tooltips_variables=[], figsize=(800, 600), output_format='svg', render_seed=42, render_iterations=100, MIN_SIZE=7, MAX_SIZE=20)
Bases:
objectCreate a Bokeh plot rapresenting the BallMapper graph.
- Parameters:
graph (NetworkX graph) – The Graph attribute of a BallMapper object.
my_palette (matplotlib palette) – The color palette used to color the nodes.
tooltips_variables (list of strings, default=None) – Which variables to show in the mouse hovertool.
figsize (tuple, default=(800, 600)) – The figure size.
output_format (string, default='svg') – The format in which the save button saves the plot.
render_seed (int, default=42) – Seed for the networkx spring_layout.
render_iterations (int, default=100) – Number of iterations for the networkx spring_layout.
MIN_SIZE (int, default=7) – Minimal size of the graph nodes.
int (MAX_SIZE;) – Maximal size of the graph nodes.
default=20 – Maximal size of the graph nodes.
- Graph
The BallMapper graph. Each node correspond to a covering ball and has attributes: ‘landmark’ the id of the corresponding landmark point ‘points covered’ the ids of the points covered by the corresponding ball
- Type:
NetworkX Graph object
- eps
The input radius of the balls.
- Type:
float
- points_covered_by_landmarks
keys: landmarks ids values: list of ids of the points covered by the corresponding ball
- Type:
dict
- add_colorbar(num_ticks, low, high)
Add a colorbar to the right side of the Bokeh plot.
- Parameters:
num_ticks (int) – Number of ticks, use a high number (100) for a continuos looking colorbar.
low (float) – Value at the bottom of the colorbar.
high (float) – Value at the top of the colorbar.
- color_by_variable(variable, MIN_VALUE=inf, MAX_VALUE=-inf, logscale=False)
Color the BallMapper Bokeh plot nodes using a specific variable.
Coloring data can be added using the BallMapper.add_coloring() method. MIN_VALUE and MAX_VALUE are computed automatically, but lower (resp. higher) values can be manually specified.
- Parameters:
variable (string) – Which coloring variable to use.
MIN_VALUE (float, default=np.inf) – Minimum value for the coloring palette.
MAX_VALUE (float, default=-np.inf) – Maximum value for the coloring palette.
logscale (bool, default=False) – Wheter to use a logscale coloring. If False, linear is used.
- color_edges()
color edges by interpolating between the nodes’ colors
- pyballmapper.plotting.init_bokeh_figure(g, background_fill_color, title, match_aspect, edge_width, edge_color, plot_height, plot_width, sizing_mode, outline_line_width, outline_line_color)
- pyballmapper.plotting.kmapper_visualize(bm, coloring_df, path_html='output.html', title=None, **kwargs)
leverages kepler-mapper visualization tool to produce an interactive html. https://kepler-mapper.scikit-tda.org
- Parameters:
bm (BallMapper) – the BallMapper graph to plot
coloring_df (pandas.DataFrame) – pandas dataframe of shape (n_samples, n_coloring_function)
path_html (str, optional) – the output file, by default ‘output.html’
title (string, optional) – title to be displayed in the top bar, by default None
- pyballmapper.plotting.pie_graph_plot(partitions, g=None, nodes=None, edges=None, graph_layout=None, radius=0.01, node_labels=None, node_scaling='old', palette=None, background_fill_color='white', title=None, match_aspect=True, edge_width=1, edge_color='black', plot_height=600, plot_width=600, sizing_mode='fixed', show_node_labels=False, outline_line_width=1, outline_line_color='black')
Produces a bokeh plot of a graph where each node is represented by a pie chart.
- Parameters:
g – networkx graph
partitions – dict of dicts such that partitions[node][class] == portion of class at node.
graph_layout – dict of size 2 arrays such that graph_layout[node] == position of node in plane.
nodes – list of nodes. If used, parameter g is ignored.
edges – list of edges. Used in conjunction with nodes. If used, parameter g is ignored.
radius – Radius of nodes. Upper bound on the radii of nodes if node_scaling is set to True.
node_labels – list of text labels for nodes. If provided, must be in same order as iteration over nodes in graph.
node_scaling –
- If set to True, nodes are scaled from
((smallest partition size)/(largest partition size))*radius to radius, with
a minimum size of nodes of radius/10 for enhanced viewability.
palette – dict with keys nodes and values bokeh colors, or list with colors with same size as number of classes present in partitions.
title – Plot’s title.
edge_width – Graph’s edge thickness.
edge_color – Graph’s edge color. Used only if sizing_mode is “fixed”.
show_node_labels – If set to True, adds node labels to the plot.
match_aspect – Preserves aspect ratio when changing size. Passed as-is to bokeh’s figure initializer.
plot_height – Plot’s height in pixels. Used only if sizing_mode is “fixed”. Passed as-is to bokeh’s figure initializer.
plot_width – Plot’s width in pixels. Passed as-is to bokeh’s figure initializer.
sizing_mode – One of “fixed”, “stretch_both”, “stretch_width”, “stretch_height”, “scale_width”, “scale_height”. Passed as-is to bokeh’s figure initializer.
outline_line_width – Thickness of the frame of the plot. Passed as-is to bokeh’s figure initializer.
outline_line_color – Color of the frame of the plot. Passed as-is to bokeh’s figure initializer.
background_fill_color – bokeh color to use for plot background. Passed as-is to bokeh’s figure initializer.