wepy.analysis.network_layouts.layout_graph module¶
Base class for generating general purpose graphs to external formats.
The primary use for this will be generating GEXF files for use in visualization.
Routines¶
LayoutGraph
- class wepy.analysis.network_layouts.layout_graph.LayoutGraph(graph)[source]¶
Bases:
object
Base class for networks that will be given layouts for visualization.
For the graph it wraps it will create a mirror graph which only has visualization specific node and edge attributes. This avoids namespace clashes between graphs.
Creates a wrapper for a graph that allows for setting of visualization properties and export to external formats without modifying the source graph.
This is done by keeping a mirrored copy of the graph, known as the viz_graph, which has all node and edge attributes removed but keeps the topology.
- Parameters:
graph (any networkx graph)
- GRAPHVIZ_COLOR = 'color'¶
- GRAPHVIZ_POSITION = 'pos'¶
- GRAPHVIZ_SHAPE = 'shape'¶
- GRAPHVIZ_SIZE = 'size'¶
- GEXF_VIZ = 'viz'¶
- GEXF_VIZ_COLOR = 'color'¶
- GEXF_VIZ_COLOR_RED = 'r'¶
- GEXF_VIZ_COLOR_GREEN = 'g'¶
- GEXF_VIZ_COLOR_BLUE = 'b'¶
- GEXF_VIZ_COLOR_ALPHA = 'a'¶
- GEXF_VIZ_POSITION = 'position'¶
- GEXF_VIZ_POSITION_X = 'x'¶
- GEXF_VIZ_POSITION_Y = 'y'¶
- GEXF_VIZ_POSITION_Z = 'z'¶
- GEXF_VIZ_SIZE = 'size'¶
- GEXF_VIZ_SHAPE = 'shape'¶
- GEXF_EDGE_THICKNESS = 'thickness'¶
- GEXF_EDGE_SHAPE = 'shape'¶
- COLOR = 'color'¶
- POSITION = 'pos'¶
- SHAPE = 'shape'¶
- SIZE = 'size'¶
- property graph¶
The source data graph the class is wrapping.
- property viz_graph¶
The mirror graph in which visualization attributes are set.
- get_node_attributes(attribute_key)[source]¶
Gets attributes from the data graph and returns as a dictionary which is compatible with the set_node_viz_attributes methods.
For instance could be used to get a ‘weight’ value and set as the color.
- set_node_viz_attributes(attribute_key, node_attribute_dict)[source]¶
Sets attributes of the viz_graph in a format agnostic way.
- set_node_positions(node_positions_dict)[source]¶
Set positions of the nodes in the viz graph in a format agnostic way.
- Parameters:
node_positions_dict (dict of node_id: position)
- set_node_colors(node_colors_dict)[source]¶
Set colors of the nodes in the viz graph in a format agnostic way.
- Parameters:
node_colors_dict (dict of node_id: color)
- set_node_sizes(node_sizes_dict)[source]¶
Set sizes of the nodes in the viz graph in a format agnostic way.
- Parameters:
node_sizes_dict (dict of node_id: int)
- set_node_shapes(node_shapes_dict)[source]¶
Set the shapes of the nodes in the viz graph in a format agnostic way.
- Parameters:
node_shapes_dict (dict of node_id: shape_spec)
- get_node_viz_attributes(attribute_key)[source]¶
Get the format agnostic attributes of nodes in the viz graph.
- get_node_colors()[source]¶
Get the format agnostic colors of the nodes in the viz graph.
- Returns:
node_colors
- Return type:
dict of node_id: color_spec
- get_node_sizes()[source]¶
Get the format agnostic size of the nodes in the viz graph.
- Returns:
node_sizes
- Return type:
dict of node_id: float
- get_node_shapes()[source]¶
Get the format agnostic shapes of the nodes in the viz graph.
- Returns:
node_shapes
- Return type:
dict of node_id: shape_spec
- classmethod feature_vector_to_gexf_viz_position(coord_vec)[source]¶
Converts an array_like of positions to the corresponding x, y, z representation for GEXF representation.
- classmethod feature_vector_to_gexf_viz_color_RGB(color_vec)[source]¶
Converts an array_like of positions to the corresponding RGB representation for GEXF representation.
- classmethod feature_vector_to_gexf_viz_color_RGBA(color_vec)[source]¶
Converts an array_like of positions to the corresponding RGBA representation for GEXF representation.
- set_node_gexf_viz(viz_key, node_dict)[source]¶
Sets GEXF formatted visualization attributes for all nodes.
GEXF has a structure where each node has a special compound ‘viz’ attribute which can have a number of special attributes for shape, position, color, size, etc.
This method just makes it easy to set one of those attributes under all nodes ‘viz’ attribute.
- set_node_gexf_positions(node_positions_dict)[source]¶
Sets GEXF specific positions attribute for visualization to nodes.
- set_node_gexf_colors_rgb(node_colors_dict)[source]¶
Sets GEXF specific RGB color attribute for visualization to nodes.
- set_node_gexf_colors_rgba(node_colors_dict)[source]¶
Sets GEXF specific RGBA color attribute for visualization to nodes.