Plotting utilities
- pyballmapper.plotting.generate_partitions(node_contents: dict[Any, list[Any]], original_element_values: dict[Any, Any]) dict[Any, dict[Any, int]]
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: networkx.Graph, my_palette: matplotlib.colors.Colormap, tooltips_variables: list[str] | None = None, figsize: tuple[int, int] = (800, 600), output_format: str = 'svg', render_seed: int = 42, render_iterations: int = 100, MIN_SIZE: int = 7, MAX_SIZE: int = 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: int, low: float, high: float) None
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: str, MIN_VALUE: float = inf, MAX_VALUE: float = -inf, logscale: bool = False) tuple[float, float]
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() None
color edges by interpolating between the nodes’ colors
- pyballmapper.plotting.init_bokeh_figure(g: networkx.Graph, background_fill_color: str, title: str | None, match_aspect: bool, edge_width: int, edge_color: str, plot_height: int, plot_width: int, sizing_mode: str, outline_line_width: int, outline_line_color: str) tuple[Any, list[float], list[float]]
- pyballmapper.plotting.kmapper_visualize(bm: BallMapper, coloring_df: pandas.DataFrame, path_html: str = 'output.html', title: str | None = None, **kwargs: Any) None
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: dict[Any, dict[Any, float]], g: nx.Graph | None = None, nodes: list[Any] | None = None, edges: list[tuple[Any, Any]] | None = None, graph_layout: dict[Any, tuple[float, float]] | None = None, radius: float = 0.01, node_labels: list[str] | None = None, node_scaling: str = 'old', palette: dict[Any, str] | list[str] | None = None, background_fill_color: str = 'white', title: str | None = None, match_aspect: bool = True, edge_width: int = 1, edge_color: str = 'black', plot_height: int = 600, plot_width: int = 600, sizing_mode: str = 'fixed', show_node_labels: bool = False, outline_line_width: int = 1, outline_line_color: str = 'black') Any
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.