easygraph.functions.drawing package
Submodules
easygraph.functions.drawing.defaults module
- easygraph.functions.drawing.defaults.default_bipartite_size(num_u: int, num_v: int, e_list: List[tuple], u_size: float | list = 1.0, u_line_width: float | list = 1.0, v_size: float | list = 1.0, v_line_width: float | list = 1.0, e_line_width: float | list = 1.0, u_font_size: float = 1.0, v_font_size: float = 1.0)[source]
- easygraph.functions.drawing.defaults.default_bipartite_strength(num_u: int, num_v: int, e_list: List[tuple], push_u_strength: float = 1.0, push_v_strength: float = 1.0, push_e_strength: float = 1.0, pull_e_strength: float = 1.0, pull_u_center_strength: float = 1.0, pull_v_center_strength: float = 1.0)[source]
- easygraph.functions.drawing.defaults.default_bipartite_style(num_u: int, num_v: int, num_e: int, u_color: str | list = 'm', v_color: str | list = 'r', e_color: str | list = 'gray', e_fill_color: str | list = 'whitesmoke')[source]
- easygraph.functions.drawing.defaults.default_hypergraph_strength(num_v: int, e_list: List[tuple], push_v_strength: float = 1.0, push_e_strength: float = 1.0, pull_e_strength: float = 1.0, pull_center_strength: float = 1.0)[source]
- easygraph.functions.drawing.defaults.default_hypergraph_style(num_v: int, num_e: int, v_color: str | list = 'r', e_color: str | list = 'gray', e_fill_color: str | list = 'whitesmoke')[source]
- easygraph.functions.drawing.defaults.default_size(num_v: int, e_list: List[tuple], v_size: float | list = 1.0, v_line_width: float | list = 1.0, e_line_width: float | list = 1.0, font_size: float | None = None)[source]
- easygraph.functions.drawing.defaults.default_strength(num_v: int, e_list: List[tuple], push_v_strength: float = 1.0, push_e_strength: float = 1.0, pull_e_strength: float = 1.0, pull_center_strength: float = 1.0)[source]
- easygraph.functions.drawing.defaults.default_style(num_v: int, num_e: int, v_color: str | list = 'r', e_color: str | list = 'gray', e_fill_color: str | list = 'whitesmoke')[source]
- easygraph.functions.drawing.defaults.fill_color(custom_color: str | list | None, default_color: Any, length: int)[source]
easygraph.functions.drawing.drawing module
- easygraph.functions.drawing.drawing.draw_SHS_center(G, SHS, rate=1, style='center')[source]
Draw the graph whose the SH Spanners are in the center, with random layout.
- Parameters:
G (graph) – A easygraph graph.
SHS (list) – The SH Spanners in graph G.
rate (float) – The proportion of visible points and edges to the total
style (string) – “side”- the label is next to the dot “center”- the label is in the center of the dot
- Returns:
graph – the graph whose the SH Spanners are in the center.
- Return type:
network
- easygraph.functions.drawing.drawing.draw_SHS_center_kk(G, SHS, rate=1, style='center')[source]
Draw the graph whose the SH Spanners are in the center, with a Kamada-Kawai force-directed layout.
- Parameters:
G (graph) – A easygraph graph.
SHS (list) – The SH Spanners in graph G.
rate (float) – The proportion of visible points and edges to the total
style (string) – “side”- the label is next to the dot “center”- the label is in the center of the dot
- Returns:
graph – the graph whose the SH Spanners are in the center.
- Return type:
network
- easygraph.functions.drawing.drawing.draw_dynamic_hypergraph(G, group_name_list=None, column_size=None, save_path=None, title_font_size=4, e_style: str = 'circle', v_label: List[str] | None = None, v_size: float | list = 2.0, v_color: str | list = 'r', v_line_width: str | list = 1.0, e_color: str | list = 'gray', e_fill_color: str | list = 'whitesmoke', e_line_width: str | list = 1.0, font_size: float = 1.0, font_family: str = 'sans-serif', push_v_strength: float = 1.0, push_e_strength: float = 1.0, pull_e_strength: float = 1.0, pull_center_strength: float = 1.0)[source]
- Parameters:
eg.Hypergraph (G)
visualize (group_name_list The groups to)
row (column_size The number of subplots placed in each)
visualization (save_path path to save)
subplot (title_font_size The font size of tilte of each)
- easygraph.functions.drawing.drawing.draw_easygraph_edges(G, pos, edgelist=None, width=1.0, edge_color='k', style='solid', alpha=None, arrowstyle=None, arrowsize=10, edge_cmap=None, edge_vmin=None, edge_vmax=None, ax=None, arrows=None, label=None, node_size=300, nodelist=None, node_shape='o', connectionstyle='arc3', min_source_margin=0, min_target_margin=0)[source]
Draw the edges of the graph G.
This draws only the edges of the graph G.
- Parameters:
G (graph) – A easygraph graph
pos (dictionary) – A dictionary with nodes as keys and positions as values. Positions should be sequences of length 2.
edgelist (collection of edge tuples (default=G.edges())) – Draw only specified edges
width (float or array of floats (default=1.0)) – Line width of edges
edge_color (color or array of colors (default='k')) – 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.
style (string or array of strings (default='solid')) – Edge line style e.g.: ‘-’, ‘–’, ‘-.’, ‘:’ or words like ‘solid’ or ‘dashed’. Can be a single style or a sequence of styles with the same length as the edge list. If less styles than edges are given the styles will cycle. If more styles than edges are given the styles will be used sequentially and not be exhausted. Also, (offset, onoffseq) tuples can be used as style instead of a strings. (See matplotlib.patches.FancyArrowPatch: linestyle)
alpha (float or array of floats (default=None)) – The edge transparency. This can be a single alpha value, in which case it will be applied to all specified edges. Otherwise, if it is an array, the elements of alpha will be applied to the colors in order (cycling through alpha multiple times if necessary).
edge_cmap (Matplotlib colormap, optional) – Colormap for mapping intensities of edges
edge_vmin (floats, optional) – Minimum and maximum for edge colormap scaling
edge_vmax (floats, optional) – Minimum and maximum for edge colormap scaling
ax (Matplotlib Axes object, optional) – Draw the graph in the specified Matplotlib axes.
arrows (bool or None, optional (default=None)) –
If None, directed graphs draw arrowheads with ~matplotlib.patches.FancyArrowPatch, while undirected graphs draw edges via ~matplotlib.collections.LineCollection for speed. If True, draw arrowheads with FancyArrowPatches (bendable and stylish). If False, draw edges using LineCollection (linear and fast).
Note: Arrowheads will be the same color as edges.
arrowstyle (str (default='-|>' for directed graphs)) –
For directed graphs and arrows==True defaults to ‘-|>’, For undirected graphs default to ‘-‘.
See matplotlib.patches.ArrowStyle for more options.
arrowsize (int (default=10)) – For directed graphs, choose the size of the arrow head’s length and width. See matplotlib.patches.FancyArrowPatch for attribute mutation_scale for more info.
connectionstyle (string (default="arc3")) – Pass the connectionstyle parameter to create curved arc of rounding radius rad. For example, connectionstyle=’arc3,rad=0.2’. See matplotlib.patches.ConnectionStyle and matplotlib.patches.FancyArrowPatch for more info.
node_size (scalar or array (default=300)) – Size of nodes. Though the nodes are not drawn with this function, the node size is used in determining edge positioning.
nodelist (list, optional (default=G.nodes())) – This provides the node order for the node_size array (if it is an array).
node_shape (string (default='o')) – The marker used for nodes, used in determining edge positioning. Specification is as a matplotlib.markers marker, e.g. one of ‘so^>v<dph8’.
label (None or string) – Label for legend
min_source_margin (int (default=0)) – The minimum margin (gap) at the beginning of the edge at the source.
min_target_margin (int (default=0)) – The minimum margin (gap) at the end of the edge at the target.
- Returns:
If
arrows=True
, a list of FancyArrowPatches is returned. Ifarrows=False
, a LineCollection is returned. Ifarrows=None
(the default), then a LineCollection is returned if G is undirected, otherwise returns a list of FancyArrowPatches.- Return type:
matplotlib.collections.LineCollection or a list of matplotlib.patches.FancyArrowPatch
Notes
For directed graphs, arrows are drawn at the head end. Arrows can be turned off with keyword arrows=False or by passing an arrowstyle without an arrow on the end.
Be sure to include node_size as a keyword argument; arrows are drawn considering the size of nodes.
Self-loops are always drawn with ~matplotlib.patches.FancyArrowPatch regardless of the value of arrows or whether G is directed. When
arrows=False
orarrows=None
and G is undirected, the FancyArrowPatches corresponding to the self-loops are not explicitly returned. They should instead be accessed via theAxes.patches
attribute (see examples).
- easygraph.functions.drawing.drawing.draw_easygraph_nodes(G, pos, nodelist=None, node_size=300, node_color='#1f78b4', node_shape='o', alpha=None, cmap=None, vmin=None, vmax=None, ax=None, linewidths=None, edgecolors=None, label=None, margins=None)[source]
Draw the nodes of the graph G.
This draws only the nodes of the graph G.
- Parameters:
G (graph) – A EasyGraph graph
pos (dictionary) – A dictionary with nodes as keys and positions as values. Positions should be sequences of length 2.
ax (Matplotlib Axes object, optional) – Draw the graph in the specified Matplotlib axes.
nodelist (list (default list(G))) – Draw only specified nodes
node_size (scalar or array (default=300)) – Size of nodes. If an array it must be the same length as nodelist.
node_color (color or array of colors (default='#1f78b4')) – Node color. Can be a single color or a sequence of colors with the same length as nodelist. 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 cmap and vmin,vmax parameters. See matplotlib.scatter for more details.
node_shape (string (default='o')) – The shape of the node. Specification is as matplotlib.scatter marker, one of ‘so^>v<dph8’.
alpha (float or array of floats (default=None)) – The node transparency. This can be a single alpha value, in which case it will be applied to all the nodes of color. Otherwise, if it is an array, the elements of alpha will be applied to the colors in order (cycling through alpha multiple times if necessary).
cmap (Matplotlib colormap (default=None)) – Colormap for mapping intensities of nodes
vmin (floats or None (default=None)) – Minimum and maximum for node colormap scaling
vmax (floats or None (default=None)) – Minimum and maximum for node colormap scaling
linewidths ([None | scalar | sequence] (default=1.0)) – Line width of symbol border
edgecolors ([None | scalar | sequence] (default = node_color)) – Colors of node borders. Can be a single color or a sequence of colors with the same length as nodelist. 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 cmap and vmin,vmax parameters. See ~matplotlib.pyplot.scatter for more details.
label ([None | string]) – Label for legend
margins (float or 2-tuple, optional) – Sets the padding for axis autoscaling. Increase margin to prevent clipping for nodes that are near the edges of an image. Values should be in the range
[0, 1]
. Seematplotlib.axes.Axes.margins()
for details. The default is None, which uses the Matplotlib default.
- Returns:
PathCollection of the nodes.
- Return type:
matplotlib.collections.PathCollection
Examples
>>> G = eg.dodecahedral_graph() >>> nodes = eg.draw_easygraph_nodes(G, pos=eg.spring_layout(G))
- easygraph.functions.drawing.drawing.draw_gm_com(G, gm_com)[source]
Draw the graph and show the communities
- Parameters:
G (graph)
gm_com (communities created by greedy modularity)
- easygraph.functions.drawing.drawing.draw_hypergraph(hg: Hypergraph, e_style: str = 'circle', v_label: List[str] | None = None, v_size: float | list = 1.0, v_color: str | list = 'r', v_line_width: str | list = 1.0, e_color: str | list = 'gray', e_fill_color: str | list = 'whitesmoke', e_line_width: str | list = 1.0, font_size: float = 1.0, font_family: str = 'sans-serif', push_v_strength: float = 1.0, push_e_strength: float = 1.0, pull_e_strength: float = 1.0, pull_center_strength: float = 1.0)[source]
Draw the hypergraph structure.
- Parameters:
hg (
eg.Hypergraph
) – The EasyGraph’s hypergraph object.e_style (
str
) – The style of hyperedges. The available styles are only'circle'
. Defaults to'circle'
.v_label (
list
) – The labels of vertices. Defaults toNone
.v_size (
float
orlist
) – The size of vertices. Defaults to1.0
.v_color (
str
orlist
) – The color of vertices. Defaults to'r'
.v_line_width (
float
orlist
) – The line width of vertices. Defaults to1.0
.e_color (
str
orlist
) –The color of hyperedges. Defaults to
'gray'
.e_fill_color (
str
orlist
) –The fill color of hyperedges. Defaults to
'whitesmoke'
.e_line_width (
float
orlist
) – The line width of hyperedges. Defaults to1.0
.font_size (
float
) – The font size of labels. Defaults to1.0
.font_family (
str
) – The font family of labels. Defaults to'sans-serif'
.push_v_strength (
float
) – The strength of pushing vertices. Defaults to1.0
.push_e_strength (
float
) – The strength of pushing hyperedges. Defaults to1.0
.pull_e_strength (
float
) – The strength of pulling hyperedges. Defaults to1.0
.pull_center_strength (
float
) – The strength of pulling vertices to the center. Defaults to1.0
.
- easygraph.functions.drawing.drawing.draw_kamada_kawai(G, rate=1, style='side')[source]
Draw the graph G with a Kamada-Kawai force-directed layout.
- Parameters:
G (graph) – A easygraph graph
rate (float) – The proportion of visible points and edges to the total
style (string) – “side”- the label is next to the dot “center”- the label is in the center of the dot
easygraph.functions.drawing.geometry module
easygraph.functions.drawing.layout module
easygraph.functions.drawing.plot module
- easygraph.functions.drawing.plot.plot_Betweenness_Centrality(G, SHS)[source]
Returns the CDF curves of “Betweenness Centralitys” of SH spanners and ordinary users in graph G.
- Parameters:
G (graph) – A easygraph graph.
SHS (list) – The SH Spanners in graph G.
- Returns:
plt – the CDF curves of “Betweenness Centrality” of SH spanners and ordinary users in graph G.
- Return type:
CDF curves
- easygraph.functions.drawing.plot.plot_Connected_Communities(G, SHS)[source]
Returns the CDF curves of “Number of Connected Communities” of SH spanners and ordinary users in graph G.
- Parameters:
G (graph) – A easygraph graph.
SHS (list) – The SH Spanners in graph G.
- Returns:
plt – the CDF curves of “Number of Connected Communities” of SH spanners and ordinary users in graph G.
- Return type:
CDF curves
- easygraph.functions.drawing.plot.plot_Followers(G, SHS)[source]
Returns the CDF curves of “Number of Followers” of SH spanners and ordinary users in graph G.
- Parameters:
G (graph) – A easygraph graph.
SHS (list) – The SH Spanners in graph G.
- Returns:
plt – the CDF curves of “Number of Followers” of SH spanners and ordinary users in graph G.
- Return type:
CDF curves
- easygraph.functions.drawing.plot.plot_Neighborhood_Followers(G, SHS)[source]
Returns the CDF curves of “Arg. Number of Followers of the Neighborhood Users” of SH spanners and ordinary users in graph G.
- Parameters:
G (graph) – A easygraph graph.
SHS (list) – The SH Spanners in graph G.
- Returns:
plt – the CDF curves of “Arg. Number of Followers of the Neighborhood Users “ of SH spanners and ordinary users in graph G.
- Return type:
CDF curves
easygraph.functions.drawing.positioning module
- easygraph.functions.drawing.positioning.circular_position(G, center=None, scale=1)[source]
Position nodes on a circle, the dimension is 2.
- Parameters:
G (easygraph.Graph or easygraph.DiGraph) – A position will be assigned to every node in G
center (array-like or None, optional (default : None)) – Coordinate pair around which to center the layout
scale (number, optional (default : 1)) – Scale factor for positions
- Returns:
pos – A dictionary of positions keyed by node
- Return type:
dict
- easygraph.functions.drawing.positioning.kamada_kawai_layout(G, dist=None, pos=None, weight='weight', scale=1, center=None, dim=2)[source]
Position nodes using Kamada-Kawai basic-length cost-function.
- Parameters:
G (graph or list of nodes) – A position will be assigned to every node in G.
dist (dict (default=None)) – A two-level dictionary of optimal distances between nodes, indexed by source and destination node. If None, the distance is computed using shortest_path_length().
pos (dict or None optional (default=None)) – Initial positions for nodes as a dictionary with node as keys and values as a coordinate list or tuple. If None, then use circular_layout() for dim >= 2 and a linear layout for dim == 1.
weight (string or None optional (default='weight')) – The edge attribute that holds the numerical value used for the edge weight. If None, then all edge weights are 1.
scale (number (default: 1)) – Scale factor for positions.
center (array-like or None) – Coordinate pair around which to center the layout.
dim (int) – Dimension of layout.
- Returns:
pos – A dictionary of positions keyed by node
- Return type:
dict
Examples
>>> pos = eg.kamada_kawai_layout(G)
- easygraph.functions.drawing.positioning.random_position(G, center=None, dim=2, random_seed=None)[source]
Returns random position for each node in graph G.
- Parameters:
G (easygraph.Graph or easygraph.DiGraph)
center (array-like or None, optional (default : None)) – Coordinate pair around which to center the layout
dim (int, optional (default : 2)) – Dimension of layout
random_seed (int or None, optional (default : None)) – Seed for RandomState instance
- Returns:
pos – A dictionary of positions keyed by node
- Return type:
dict
- easygraph.functions.drawing.positioning.rescale_position(pos, scale=1)[source]
Returns scaled position array to (-scale, scale) in all axes.
- Parameters:
pos (numpy array) – positions to be scaled. Each row is a position.
scale (number, optional (default : 1)) – The size of the resulting extent in all directions.
- Returns:
pos – scaled positions. Each row is a position.
- Return type:
numpy array
- easygraph.functions.drawing.positioning.shell_position(G, nlist=None, scale=1, center=None)[source]
Position nodes in concentric circles, the dimension is 2.
- Parameters:
G (easygraph.Graph or easygraph.DiGraph)
nlist (list of lists or None, optional (default : None)) – List of node lists for each shell.
scale (number, optional (default : 1)) – Scale factor for positions.
center (array-like or None, optional (default : None)) – Coordinate pair around which to center the layout.
- Returns:
pos – A dictionary of positions keyed by node
- Return type:
dict
Notes
This algorithm currently only works in two dimensions and does not try to minimize edge crossings.
easygraph.functions.drawing.simulator module
easygraph.functions.drawing.utils module
- easygraph.functions.drawing.utils.apply_alpha(colors, alpha, elem_list, cmap=None, vmin=None, vmax=None)[source]
Apply an alpha (or list of alphas) to the colors provided.
- Parameters:
colors (color string or array of floats (default='r')) – Color of element. Can be a single color format string, or a sequence of colors with the same length as nodelist. If numeric values are specified they will be mapped to colors using the cmap and vmin,vmax parameters. See matplotlib.scatter for more details.
alpha (float or array of floats) – Alpha values for elements. This can be a single alpha value, in which case it will be applied to all the elements of color. Otherwise, if it is an array, the elements of alpha will be applied to the colors in order (cycling through alpha multiple times if necessary).
elem_list (array of networkx objects) – The list of elements which are being colored. These could be nodes, edges or labels.
cmap (matplotlib colormap) – Color map for use if colors is a list of floats corresponding to points on a color mapping.
vmin (float) – Minimum and maximum values for normalizing colors if a colormap is used
vmax (float) – Minimum and maximum values for normalizing colors if a colormap is used
- Returns:
rgba_colors – Array containing RGBA format values for each of the node colours.
- Return type:
numpy ndarray
- easygraph.functions.drawing.utils.draw_circle_edge(ax: Axes, v_coor: List[Tuple[float, float]], v_size: list, e_list: List[Tuple[int, int]], e_color: list, e_fill_color: list, e_line_width: list)[source]
- easygraph.functions.drawing.utils.draw_line_edge(ax: Axes, v_coor: array, v_size: list, e_list: List[Tuple[int, int]], show_arrow: bool, e_color: list, e_line_width: list)[source]
- easygraph.functions.drawing.utils.draw_vertex(ax: Axes, v_coor: List[Tuple[float, float]], v_label: List[str] | None, font_size: int, font_family: str, v_size: list, v_color: list, edgecolors, v_line_width: list)[source]
- easygraph.functions.drawing.utils.edge_list_to_incidence_matrix(num_v: int, e_list: List[tuple]) ndarray [source]
- easygraph.functions.drawing.utils.hull_layout(n_v, e_list, pos, v_size, radius_increment=0.3)[source]