Loading phasik/drawing/drawing.py +15 −6 Original line number Diff line number Diff line Loading @@ -32,14 +32,18 @@ def plot_events( alpha=1, va="bottom", ): """Plot events as vertical lines on axes """Visualize the occurence of events as vertical lines. This function was designed to be used in complement to another function `plot_cluster_sets` that draws objects over time (horizontal axis). The vertical lines are drawn at the horizontal value corresponding to the time of occurrence of the event. Parameters ---------- events : list of tuples (time, name, line_style) time - time at which the event occurred name - the name of the event line_style - any string accepted by matplotlib.lines.Line2D.set_linestyle * time - time at which the event occurred * name - the name of the event * line_style - any string accepted by matplotlib.lines.Line2D.set_linestyle ax : matplotlib.Axes, optional Axes on which to plot the events text_y_pos : float, optional Loading @@ -61,6 +65,7 @@ def plot_events( See Also -------- plot_phases plot_cluster_sets """ if ax is None: Loading Loading @@ -152,7 +157,11 @@ def plot_events( def plot_phases(phases, ax=None, y_pos=None, ymin=0, ymax=1, t_offset=0): """Plot phases as shaded regions on axes """Visualize temporal phases as shaded intervals This function was designed to be used in complement to another function `plot_cluster_sets` that draws objects over time (horizontal axis). The phases are drawn as shaded regions spanning the time interval corresponding to the phases. Parameters ---------- Loading Loading @@ -314,7 +323,7 @@ def threshold_plot( def plot_edge_series(temporal_network, edges, ax=None, **kwargs): """Plot timeseries of edge weights, for the specified edges """Draw time series of edge weights, for the specified edges Parameters ---------- Loading phasik/drawing/drawing_clusters.py +22 −6 Original line number Diff line number Diff line Loading @@ -89,7 +89,7 @@ def plot_randindex_bars_over_methods_and_sizes( heights, width, label=method, **kwargs **kwargs, ) ax.set_xticks(xticks) Loading @@ -105,7 +105,7 @@ def plot_cluster_set( cmap=mpl.colormaps["tab10"], number_of_colors=10, colors=None, **kwargs **kwargs, ): """Plots this cluster set as a scatter graph Loading Loading @@ -156,7 +156,7 @@ def plot_cluster_set( cmap=cmap, vmin=1, vmax=number_of_colors, **kwargs **kwargs, ) return ax Loading Loading @@ -297,7 +297,9 @@ def plot_dendrogram( return ax def plot_average_silhouettes(cluster_sets, ax=None, c="k", marker="o", ls="-", **kwargs): def plot_average_silhouettes( cluster_sets, ax=None, c="k", marker="o", ls="-", **kwargs ): """Plot the average silhouettes across this range of cluster sets Parameters Loading @@ -317,7 +319,14 @@ def plot_average_silhouettes(cluster_sets, ax=None, c="k", marker="o", ls="-", * if ax is None: ax = plt.gca() ax.plot(cluster_sets.silhouettes_average, cluster_sets.ns_max, c=c, marker=marker, ls=ls, **kwargs) ax.plot( cluster_sets.silhouettes_average, cluster_sets.ns_max, c=c, marker=marker, ls=ls, **kwargs, ) ax.set_xlabel("Average silhouette") return ax Loading @@ -343,7 +352,14 @@ def plot_ns_clusters(cluster_sets, ax=None, c="k", marker="o", ls="-", **kwargs) if ax is None: ax = plt.gca() ax.plot(cluster_sets.n_clusters, cluster_sets.ns_max, c=c, marker=marker, ls=ls, **kwargs) ax.plot( cluster_sets.n_clusters, cluster_sets.ns_max, c=c, marker=marker, ls=ls, **kwargs, ) return ax Loading phasik/drawing/drawing_networks.py +24 −64 Original line number Diff line number Diff line Loading @@ -69,14 +69,15 @@ def standard_label_params(color): def draw_graph( graph, ax=None, label_nodes=True, color="mediumseagreen", pos=None, color="mediumseagreen", edge_widths=None, edge_colors=None, edge_cmap=None, edge_vmin=None, edge_vmax=None, label_nodes=True, colorbar=True, ): """Basic graph drawing function Loading @@ -86,12 +87,10 @@ def draw_graph( Graph to visualise ax : matplotlib.Axes, optional Axes on which to draw the graph label_nodes : bool, optional Whether to label the nodes or just leave them as small circles (default True) pos : dict Dictionary of node positions of the form {node_id : (x, y)} color : str, optional Color to use for the graph nodes and edges (default 'mediumseagreen') pos : dict Dictionary of node positions edge_widths: float or array of floats Line width of edges edge_colors: color or array of colors Loading @@ -103,10 +102,15 @@ def draw_graph( Colormap for mapping intensities of edges edge_vmin,edge_vmax: floats, optional Minimum and maximum for edge colormap scaling label_nodes : bool, optional Whether to label the nodes or just leave them as small circles (default True) colorbar : bool, optional Wether to draw a colorbar Returns ------- None matplotlib.axes.Axes The axis object to draw on """ if ax is None: Loading @@ -115,62 +119,6 @@ def draw_graph( if pos is None: pos = nx.spring_layout(graph) _draw_graph( graph, pos, ax, label_nodes, color, edge_widths, edge_colors, edge_cmap, edge_vmin, edge_vmax, ) def _draw_graph( graph, pos, ax, label_nodes, color, edge_widths=1, edge_colors="k", edge_cmap=None, edge_vmin=None, edge_vmax=None, ): """Plots a networkx.Graph with a predefined style Parameters ---------- graph : networkx.Graph Graph to visualise pos : dict Dictionary of positions used by plotting function in networkx ax : maplotlib.axis Axes on which to plot label_nodes : bool If True, plot node labels color : str Color used for nodes and edges edge_widths: float or array of floats Line width of edges edge_colors: color or array of colors Edge color. Can be a single color or a sequence of colors with the same length as edgelist. Color can be string or rgb (or rgba) tuple of floats from 0-1. If numeric values are specified they will be mapped to colors using the edge_cmap and edge_vmin,edge_vmax parameters. edge_cmap: Matplotlib colormap, optional Colormap for mapping intensities of edges edge_vmin,edge_vmax: floats, optional Minimum and maximum for edge colormap scaling Returns ------- """ params_nodes = standard_node_params(color) params_edges = standard_edge_params(color) params_labels = standard_label_params(color) Loading @@ -193,10 +141,13 @@ def _draw_graph( if label_nodes: nx.draw_networkx_labels(graph, ax=ax, pos=pos, **params_labels) if colorbar: if edge_colors is not None: if len(edge_colors) == len(graph.edges): plt.colorbar(im, ax=ax, label="edge color scale") return ax def highlight_subgraphs(graphs, colors, ax=None, pos=None, label_nodes=True): """Draw multiple nested subgraphs on the same axes Loading Loading @@ -226,7 +177,16 @@ def highlight_subgraphs(graphs, colors, ax=None, pos=None, label_nodes=True): pos = nx.spring_layout(graphs[0]) for graph, color in zip(graphs, colors): _draw_graph(graph, pos, ax, label_nodes, color, edge_colors=color) draw_graph( graph=graph, pos=pos, ax=ax, label_nodes=label_nodes, color=color, edge_colors=color, ) return def animate_temporal_network( Loading Loading
phasik/drawing/drawing.py +15 −6 Original line number Diff line number Diff line Loading @@ -32,14 +32,18 @@ def plot_events( alpha=1, va="bottom", ): """Plot events as vertical lines on axes """Visualize the occurence of events as vertical lines. This function was designed to be used in complement to another function `plot_cluster_sets` that draws objects over time (horizontal axis). The vertical lines are drawn at the horizontal value corresponding to the time of occurrence of the event. Parameters ---------- events : list of tuples (time, name, line_style) time - time at which the event occurred name - the name of the event line_style - any string accepted by matplotlib.lines.Line2D.set_linestyle * time - time at which the event occurred * name - the name of the event * line_style - any string accepted by matplotlib.lines.Line2D.set_linestyle ax : matplotlib.Axes, optional Axes on which to plot the events text_y_pos : float, optional Loading @@ -61,6 +65,7 @@ def plot_events( See Also -------- plot_phases plot_cluster_sets """ if ax is None: Loading Loading @@ -152,7 +157,11 @@ def plot_events( def plot_phases(phases, ax=None, y_pos=None, ymin=0, ymax=1, t_offset=0): """Plot phases as shaded regions on axes """Visualize temporal phases as shaded intervals This function was designed to be used in complement to another function `plot_cluster_sets` that draws objects over time (horizontal axis). The phases are drawn as shaded regions spanning the time interval corresponding to the phases. Parameters ---------- Loading Loading @@ -314,7 +323,7 @@ def threshold_plot( def plot_edge_series(temporal_network, edges, ax=None, **kwargs): """Plot timeseries of edge weights, for the specified edges """Draw time series of edge weights, for the specified edges Parameters ---------- Loading
phasik/drawing/drawing_clusters.py +22 −6 Original line number Diff line number Diff line Loading @@ -89,7 +89,7 @@ def plot_randindex_bars_over_methods_and_sizes( heights, width, label=method, **kwargs **kwargs, ) ax.set_xticks(xticks) Loading @@ -105,7 +105,7 @@ def plot_cluster_set( cmap=mpl.colormaps["tab10"], number_of_colors=10, colors=None, **kwargs **kwargs, ): """Plots this cluster set as a scatter graph Loading Loading @@ -156,7 +156,7 @@ def plot_cluster_set( cmap=cmap, vmin=1, vmax=number_of_colors, **kwargs **kwargs, ) return ax Loading Loading @@ -297,7 +297,9 @@ def plot_dendrogram( return ax def plot_average_silhouettes(cluster_sets, ax=None, c="k", marker="o", ls="-", **kwargs): def plot_average_silhouettes( cluster_sets, ax=None, c="k", marker="o", ls="-", **kwargs ): """Plot the average silhouettes across this range of cluster sets Parameters Loading @@ -317,7 +319,14 @@ def plot_average_silhouettes(cluster_sets, ax=None, c="k", marker="o", ls="-", * if ax is None: ax = plt.gca() ax.plot(cluster_sets.silhouettes_average, cluster_sets.ns_max, c=c, marker=marker, ls=ls, **kwargs) ax.plot( cluster_sets.silhouettes_average, cluster_sets.ns_max, c=c, marker=marker, ls=ls, **kwargs, ) ax.set_xlabel("Average silhouette") return ax Loading @@ -343,7 +352,14 @@ def plot_ns_clusters(cluster_sets, ax=None, c="k", marker="o", ls="-", **kwargs) if ax is None: ax = plt.gca() ax.plot(cluster_sets.n_clusters, cluster_sets.ns_max, c=c, marker=marker, ls=ls, **kwargs) ax.plot( cluster_sets.n_clusters, cluster_sets.ns_max, c=c, marker=marker, ls=ls, **kwargs, ) return ax Loading
phasik/drawing/drawing_networks.py +24 −64 Original line number Diff line number Diff line Loading @@ -69,14 +69,15 @@ def standard_label_params(color): def draw_graph( graph, ax=None, label_nodes=True, color="mediumseagreen", pos=None, color="mediumseagreen", edge_widths=None, edge_colors=None, edge_cmap=None, edge_vmin=None, edge_vmax=None, label_nodes=True, colorbar=True, ): """Basic graph drawing function Loading @@ -86,12 +87,10 @@ def draw_graph( Graph to visualise ax : matplotlib.Axes, optional Axes on which to draw the graph label_nodes : bool, optional Whether to label the nodes or just leave them as small circles (default True) pos : dict Dictionary of node positions of the form {node_id : (x, y)} color : str, optional Color to use for the graph nodes and edges (default 'mediumseagreen') pos : dict Dictionary of node positions edge_widths: float or array of floats Line width of edges edge_colors: color or array of colors Loading @@ -103,10 +102,15 @@ def draw_graph( Colormap for mapping intensities of edges edge_vmin,edge_vmax: floats, optional Minimum and maximum for edge colormap scaling label_nodes : bool, optional Whether to label the nodes or just leave them as small circles (default True) colorbar : bool, optional Wether to draw a colorbar Returns ------- None matplotlib.axes.Axes The axis object to draw on """ if ax is None: Loading @@ -115,62 +119,6 @@ def draw_graph( if pos is None: pos = nx.spring_layout(graph) _draw_graph( graph, pos, ax, label_nodes, color, edge_widths, edge_colors, edge_cmap, edge_vmin, edge_vmax, ) def _draw_graph( graph, pos, ax, label_nodes, color, edge_widths=1, edge_colors="k", edge_cmap=None, edge_vmin=None, edge_vmax=None, ): """Plots a networkx.Graph with a predefined style Parameters ---------- graph : networkx.Graph Graph to visualise pos : dict Dictionary of positions used by plotting function in networkx ax : maplotlib.axis Axes on which to plot label_nodes : bool If True, plot node labels color : str Color used for nodes and edges edge_widths: float or array of floats Line width of edges edge_colors: color or array of colors Edge color. Can be a single color or a sequence of colors with the same length as edgelist. Color can be string or rgb (or rgba) tuple of floats from 0-1. If numeric values are specified they will be mapped to colors using the edge_cmap and edge_vmin,edge_vmax parameters. edge_cmap: Matplotlib colormap, optional Colormap for mapping intensities of edges edge_vmin,edge_vmax: floats, optional Minimum and maximum for edge colormap scaling Returns ------- """ params_nodes = standard_node_params(color) params_edges = standard_edge_params(color) params_labels = standard_label_params(color) Loading @@ -193,10 +141,13 @@ def _draw_graph( if label_nodes: nx.draw_networkx_labels(graph, ax=ax, pos=pos, **params_labels) if colorbar: if edge_colors is not None: if len(edge_colors) == len(graph.edges): plt.colorbar(im, ax=ax, label="edge color scale") return ax def highlight_subgraphs(graphs, colors, ax=None, pos=None, label_nodes=True): """Draw multiple nested subgraphs on the same axes Loading Loading @@ -226,7 +177,16 @@ def highlight_subgraphs(graphs, colors, ax=None, pos=None, label_nodes=True): pos = nx.spring_layout(graphs[0]) for graph, color in zip(graphs, colors): _draw_graph(graph, pos, ax, label_nodes, color, edge_colors=color) draw_graph( graph=graph, pos=pos, ax=ax, label_nodes=label_nodes, color=color, edge_colors=color, ) return def animate_temporal_network( Loading