Attempting to create a custom Graph class that can load, manipulate, and visualize graphs from .dot files these are basic graphs right now. More...
Public Member Functions | |
__init__ (self) | |
Initalize an empty graph. | |
load_from_dot (self, file_path) | |
Loads a graph from a .dot file. | |
add_node (self, node_id, **attributes) | |
Add a node to the current graph. | |
add_edge (self, start, dest, **attributes) | |
Add an edge to the graph. | |
save_to_dot (self, file_path) | |
Save the current graph to a .dot file. | |
display_with_graphviz (self, layout="dot", format="png", show=True, output_file=None) | |
Visualize with GraphViz by creating a png. | |
display_with_matplotlib (self, layout=None, node_size=300, node_color="skyblue", edge_color="black", with_labels=True, font_size=10, figsize=(8, 6), output_file=None) | |
Trying and seeing how visualization of graphs with Matplotlib looks like. | |
get_node_count (self) | |
return the number of nodes in the graph. | |
get_edge_count (self) | |
return the number of edges in the graph. | |
get_nodes (self) | |
return the list of nodes in the graph | |
get_edges (self) | |
return the list of edges in the graph | |
get_successors (self, node) | |
return successors of a node | |
get_predecessors (self, node) | |
reutrn the predessors of a node | |
get_adjacency_matrix (self, weight=None) | |
return the adjacency matrix of the graph | |
Public Attributes | |
graph = nx.DiGraph() | |
Attempting to create a custom Graph class that can load, manipulate, and visualize graphs from .dot files these are basic graphs right now.
Definition at line 12 of file graph_utils.py.
graph_utils.Graph.__init__ | ( | self | ) |
Initalize an empty graph.
self | the current graph object |
Definition at line 18 of file graph_utils.py.
graph_utils.Graph.add_edge | ( | self, | |
start, | |||
dest, | |||
** | attributes ) |
Add an edge to the graph.
self | the current graph object |
start | The node to start at |
dest | the node to end at |
**attributes | optional edge features |
Definition at line 65 of file graph_utils.py.
References add_edge(), and graph.
Referenced by add_edge().
graph_utils.Graph.add_node | ( | self, | |
node_id, | |||
** | attributes ) |
Add a node to the current graph.
self | the current graph object |
node_id | tage for the node |
**attributes | optional node features |
Definition at line 55 of file graph_utils.py.
References add_node(), and graph.
Referenced by add_node().
graph_utils.Graph.display_with_graphviz | ( | self, | |
layout = "dot", | |||
format = "png", | |||
show = True, | |||
output_file = None ) |
Visualize with GraphViz by creating a png.
layout | GraphViz layout type ('dot', 'neato', 'fdp', 'sfdp', 'twopi', 'circo') |
format | Output format ('png', 'svg', 'pdf', etc.) |
show | Display the graph (if true) or return the image data (false) |
Definition at line 95 of file graph_utils.py.
References graph.
graph_utils.Graph.display_with_matplotlib | ( | self, | |
layout = None, | |||
node_size = 300, | |||
node_color = "skyblue", | |||
edge_color = "black", | |||
with_labels = True, | |||
font_size = 10, | |||
figsize = (8, 6), | |||
output_file = None ) |
Trying and seeing how visualization of graphs with Matplotlib looks like.
layout | the layout algorithm used |
node_size | size of nodes |
node_color | color of nodes |
edge_color | color of edges |
with_labels | whether to display node labels |
font_size | size of node labels |
figsize | figure size |
Definition at line 149 of file graph_utils.py.
References graph.
graph_utils.Graph.get_adjacency_matrix | ( | self, | |
weight = None ) |
return the adjacency matrix of the graph
weight | Edge data weight. If none, all adges have weight 1. If a string, the edge attribute. If a function, the value returned by the function is used |
Definition at line 276 of file graph_utils.py.
References get_nodes(), and graph.
graph_utils.Graph.get_edge_count | ( | self | ) |
return the number of edges in the graph.
Definition at line 239 of file graph_utils.py.
References graph.
graph_utils.Graph.get_edges | ( | self | ) |
return the list of edges in the graph
Definition at line 253 of file graph_utils.py.
References graph.
graph_utils.Graph.get_node_count | ( | self | ) |
return the number of nodes in the graph.
Definition at line 232 of file graph_utils.py.
References graph.
graph_utils.Graph.get_nodes | ( | self | ) |
return the list of nodes in the graph
Definition at line 246 of file graph_utils.py.
References graph.
Referenced by get_adjacency_matrix().
graph_utils.Graph.get_predecessors | ( | self, | |
node ) |
reutrn the predessors of a node
node | the node which predecessors will be checked from |
Definition at line 268 of file graph_utils.py.
References graph.
graph_utils.Graph.get_successors | ( | self, | |
node ) |
return successors of a node
node | the node which will be check for successor |
Definition at line 260 of file graph_utils.py.
References graph.
graph_utils.Graph.load_from_dot | ( | self, | |
file_path ) |
Loads a graph from a .dot file.
file_path | Path to the .dot file |
Definition at line 26 of file graph_utils.py.
References graph.
graph_utils.Graph.save_to_dot | ( | self, | |
file_path ) |
Save the current graph to a .dot file.
self | the current graph object |
file_path | output file path |
Definition at line 76 of file graph_utils.py.
References graph.
graph_utils.Graph.graph = nx.DiGraph() |
Definition at line 24 of file graph_utils.py.
Referenced by add_edge(), add_node(), display_with_graphviz(), display_with_matplotlib(), get_adjacency_matrix(), get_edge_count(), get_edges(), get_node_count(), get_nodes(), get_predecessors(), get_successors(), load_from_dot(), and save_to_dot().