pytspl.plot

Module for plotting simplicial complexes.

Submodules

Classes

SCPlot

Class for plotting simplicial complexes.

Package Contents

class pytspl.plot.SCPlot(simplicial_complex: pytspl.simplicial_complex.SimplicialComplex, coordinates: dict = None)[source]

Class for plotting simplicial complexes.

sc
pos
_init_axes(ax) dict[source]

Initialize the axes for the plot. The axis limits are set to the bounding box of the nodes.

Args:

ax (matplotlib.axes.Axes): The axes object.

Returns:

dict: The layout of the nodes.

create_edge_flow(flow: numpy.ndarray) dict[source]

Create a dictionary of edge flows from the flow array.

Args:

flow (np.ndarray): The flow on the edges.

Returns:

dict: The edge flow dictionary.

draw_sc_nodes(node_size: int = 300, node_color: str = '#ff7f0e', node_edge_colors: str = 'black', font_size: float = 12, font_color: str = 'k', font_weight: str = 'normal', cmap=plt.cm.Blues, vmin=None, vmax=None, alpha: float = 0.8, margins=None, with_labels: bool = False, ax=None) None[source]

Draw the nodes of the simplicial complex.

Args:

node_size (int, optional): The size of the nodes. Defaults to 300. node_color (str, optional): The color of the nodes. Defaults to ‘#ff7f0e’. node_edge_colors (str, optional): The color of the node edges. Defaults to ‘black’. font_size (float, optional): The font size of the node labels. Defaults to 12. font_color (str, optional): The color of the node labels. Defaults to ‘k’. font_weight (str, optional): The font weight of the node labels. Defaults to ‘normal’. cmap (mpl.colors.Colormap, optional): The color map. Defaults to plt.cm.Blues. vmin (float, optional): The minimum value for the color map. Defaults to None. vmax (float, optional): The maximum value for the color map. Defaults to None. alpha (float, optional): The transparency of the nodes. Defaults to 0.8. margins (float, optional): The margins of the plot. Defaults to None. with_labels (bool, optional): Whether to show the node labels. Defaults to False. ax (matplotlib.axes.Axes, optional): The axes object. Defaults to None.

_draw_node_labels(font_size: float = 12, font_color: str = 'k', font_weight: str = 'normal', alpha=None) None[source]

Draw the labels of the nodes.

Args:

font_size (float, optional): The font size of the node labels. Defaults to 12. font_color (str, optional): The color of the node labels. Defaults to ‘k’. font_weight (str, optional): The font weight of the node labels. Defaults to ‘normal’. alpha (float, optional): The transparency of the node labels. Defaults to None.

draw_sc_edges(edge_flow: dict = None, edge_color: str = 'lightblue', edge_width: float = 1.0, arrowsize: int = 10, edge_cmap=plt.cm.Blues, edge_vmin=None, edge_vmax=None, directed: bool = True, alpha: float = 0.8, ax=None) None[source]

Draw the edges of the simplicial complex.

Args:

edge_flow (dict, optional): The flow of the edges. e.g. {(0, 1): 0.5, (1, 2): 0.3, (2, 0): 0.2}. Defaults to None. edge_color (str, optional): The color of the edges. Defaults to ‘lightblue’. edge_width (float, optional): The width of the edges. Defaults to 1.0. arrowsize (int, optional): The size of the arrows. Defaults to 10. edge_cmap (mpl.colors.Colormap, optional): The color map of the edges. Defaults to plt.cm.Blues. edge_vmin (float, optional): The minimum value for the color map. Defaults to None. edge_vmax (float, optional): The maximum value for the color map. Defaults to None. directed (bool, optional): Whether the edges are directed. Defaults to True. alpha (float, optional): The transparency of the edges. Defaults to 0.8. ax (matplotlib.axes.Axes, optional): The axes object. Defaults to None.

_calculate_edge_label_position(src: tuple, dest: tuple, offset: float) tuple[source]

Calculate the position of the edge label based on the edge position.

draw_edge_labels(edge_labels: dict, font_size: int = 10, font_color: str = 'k', font_weight: str = 'normal', offset=0.15, alpha=None, ax=None) dict[source]

Draw the labels (flow) of the edges.

Args:

edge_labels (dict): The labels of the edges. e.g. {(0, 1): 0.5, (1, 2): 0.3, (2, 0): 0.2} Defaults to None. font_size (int, optional): The font size of the labels. Defaults to 10. font_color (str, optional): The color of the labels. Defaults to ‘k’. font_weight (str, optional): The font weight of the labels. Defaults to ‘normal’. offset (float, optional): The offset of the labels from the center of the edge. Defaults to 0.15. alpha (float, optional): The transparency of the labels. Defaults to None. ax (matplotlib.axes.Axes, optional): The axes object. Defaults to None.

draw_network(edge_flow=None, directed: bool = True, with_labels: bool = True, ax=None, **kwargs) None[source]

Draw the simplicial complex network with edge flow. If the flow is not provided, the network is drawn without flow.

Args:

edge_flow (dict, np.ndarray, list, optional): The labels of the edges. e.g. {(0, 1): 0.5, (1, 2): 0.3, (2, 0): 0.2}. You can also provide a numpy array of the flow. Defaults to None. directed (bool, optional): Whether the edges are directed. Defaults to True. with_labels (bool, optional): Whether to show the node labels. Defaults to True. ax (matplotlib.axes.Axes, optional): The axes object. Defaults to None.

Node kwargs:

node_size (int, optional): The size of the nodes. Defaults to 300. node_color (str, optional): The color of the nodes. Defaults to ‘#ff7f0e’. node_edge_colors (str, optional): The color of the node edges. Defaults to ‘black’. font_size (float, optional): The font size of the node labels. Defaults to 12. font_color (str, optional): The color of the node labels. Defaults to ‘k’. font_weight (str, optional): The font weight of the node labels. Defaults to ‘normal’. cmap (mpl.colors.Colormap, optional): The color map. Defaults to plt.cm.Blues. vmin (float, optional): The minimum value for the color map. Defaults to None. vmax (float, optional): The maximum value for the color map. Defaults to None. alpha (float, optional): The transparency of the nodes. Defaults to 0.8. margins (float, optional): The margins of the plot. Defaults to None.

Edge kwargs:

edge_color (str, optional): The color of the edges. Defaults to ‘lightblue’. edge_width (float, optional): The width of the edges. Defaults to 1.0. arrowsize (int, optional): The size of the arrows. Defaults to 10. edge_cmap (mpl.colors.Colormap, optional): The color map of the edges. Defaults to plt.cm.Blues. edge_vmin (float, optional): The minimum value for the color map. Defaults to None. edge_vmax (float, optional): The maximum value for the color map. Defaults to None. directed (bool, optional): Whether the edges are directed. Defaults to True. alpha (float, optional): The transparency of the edges. Defaults to 0.8.

Edge label kwargs:

font_size (int, optional): The font size of the labels. Defaults to 10. font_color (str, optional): The color of the labels. Defaults to ‘k’. font_weight (str, optional): The font weight of the labels. Defaults to ‘normal’. offset (float, optional): The offset of the labels from the center of the edge. Defaults to 0.15. alpha (float, optional): The transparency of the labels. Defaults to None.

draw_hodge_decomposition(flow: numpy.ndarray, component=None, round_fig: bool = True, round_sig_fig: int = 2, figsize=(15, 5), font_dict={'fontsize': 20}) None[source]

Draw the Hodge decomposition of the flow.

Args:

flow (np.ndarray): The flow on the edges. component (str, optional): The component of the flow to draw. If None, all three components are drawn. Defaults to None. round_fig (bool, optional): Whether to round the figures. Defaults to True. round_sig_fig (int, optional): The number of significant figures to round to. Defaults to 2. figsize (tuple, optional): The size of the figure. Defaults to (15, 5). font_dict (dict, optional): The font dictionary. Defaults to {“fontsize”: 20}.

Raises:

ValueError: If an invalid component is provided.

draw_eigenvectors(component: str, eigenvector_indices: numpy.ndarray = [], round_fig: bool = True, round_sig_fig: int = 2, with_labels: bool = True, figsize=(15, 5), font_dict={'fontsize': 20})[source]

Draw the eigenvectors for the given component and eigenvalue indices using eigendecomposition.

Args:

component (str): The component of the eigenvectors to draw. eigenvector_indices (np.ndarray, optional): The indices of the eigenvectors to draw. Defaults to []. round_fig (bool, optional): Whether to round the figures. Defaults to True. round_sig_fig (int, optional): The number of significant figures to round to. Defaults to 2. with_labels (bool, optional): Whether to show the node labels. Defaults to True. figsize (tuple, optional): The size of the figure. Defaults to (15, 5). font_dict (dict, optional): The font dictionary. Defaults to {“fontsize”: 20}.