powergrid_synth.core.visualization

The visualization module contains various methods for plots.

Module Contents

class powergrid_synth.core.visualization.GridVisualizer[source]

Visualization module for synthetic power grids. Allows plotting the grid with different layouts including Yifan Hu, Kamada-Kawai, and Voltage Layered.

_create_interactive_window(graph, title, figsize)[source]

Helper to create a figure with a Dropdown menu for layout selection.

Parameters:
  • graph (networkx.Graph)

  • title (str)

  • figsize (Tuple[int, int])

_draw_bus_types_on_ax(ax, graph, layout_name, title, legend_loc='center left', legend_bbox=(1, 0.5), bbox_transform=None, show_impedance=False)[source]

Helper to draw bus type visualization on a specific axis.

Parameters:
  • graph (networkx.Graph)

  • layout_name (str)

  • title (str)

  • show_impedance (bool)

_draw_edges_impedance(ax, grid, pos, alpha=0.8)[source]

Helper to draw edges colored by impedance.

_draw_graph_on_ax(ax, graph, layout_name, title, show_labels, legend_loc='upper right', legend_bbox=None, bbox_transform=None, show_impedance=False)[source]

Helper to draw graph on a specific axis.

Parameters:

show_impedance (bool)

_find_tree_root(tree)[source]

Find the best root for a tree: prefer lowest voltage_level, then highest degree.

Parameters:

tree (networkx.Graph)

Return type:

Any

_get_layered_layout(graph)[source]

Custom layout: Places nodes in horizontal bands based on voltage level.

Parameters:

graph (networkx.Graph)

Return type:

Dict[int, numpy.ndarray]

_get_node_colors(graph)[source]

Assigns colors to nodes based on their ‘voltage_level’ attribute.

Parameters:

graph (networkx.Graph)

Return type:

List[Any]

_hierarchical_tree_layout(graph, layer_sep=1.0, node_sep=1.0)[source]

Hierarchical top-down layout suitable for tree/forest graphs.

Root at the top, children below. Handles disconnected forests by placing each component side-by-side.

Parameters:
  • graph (networkx.Graph)

  • layer_sep (float)

  • node_sep (float)

Return type:

Dict[Any, numpy.ndarray]

_radial_tree_layout(graph, radius_step=1.0)[source]

Radial layout suitable for tree/forest graphs.

Root at the center, each BFS layer on a concentric circle. Handles disconnected forests by rotating each component into its own sector.

Parameters:
  • graph (networkx.Graph)

  • radius_step (float)

Return type:

Dict[Any, numpy.ndarray]

_yifan_hu_layout(G, iterations=100, k=None)[source]

Implementation of the Yifan Hu force-directed layout algorithm.

Parameters:
  • G (networkx.Graph)

  • iterations (int)

  • k (Optional[float])

Return type:

Dict[int, numpy.ndarray]

plot_bus_types(graph, layout='kamada_kawai', title='Bus Type Visualization', show_impedance=False, figsize=(12, 10))[source]

Visualizes the grid coloring nodes by their Bus Type (Static). Option to show impedance on edges.

Parameters:
  • graph (networkx.Graph)

  • layout (str)

  • title (str)

  • show_impedance (bool)

  • figsize (Tuple[int, int])

plot_grid(graph, layout='kamada_kawai', title='Grid', show_labels=False, show_bus_types=False, show_impedance=False, figsize=(12, 10))[source]

Static plot function for grid topology. Options allow overlaying bus types or impedance features.

Parameters:
  • graph (networkx.Graph)

  • layout (str)

  • title (str)

  • show_labels (bool)

  • show_bus_types (bool)

  • show_impedance (bool)

  • figsize (Tuple[int, int])

plot_impedance(grid, layout='kamada_kawai', title='Transmission Line Impedance', figsize=(12, 10))[source]

Plots the grid with edges colored by their impedance magnitude (Z). Blue = Low Impedance (Strong), Red = High Impedance (Weak).

Parameters:
  • grid (networkx.Graph)

  • layout (str)

  • title (str)

  • figsize (Tuple[int, int])

plot_interactive(graph, title='Interactive Grid', figsize=(14, 10))[source]

Opens an interactive window for the full grid.

Parameters:
  • graph (networkx.Graph)

  • title (str)

  • figsize (Tuple[int, int])

plot_interactive_bus_types(graph, title='Interactive Bus Type Visualization', figsize=(14, 10))[source]

Opens an interactive window for Bus Type Visualization with layout selection.

Parameters:
  • graph (networkx.Graph)

  • title (str)

  • figsize (Tuple[int, int])

plot_interactive_voltage_level(graph, level, title=None, figsize=(12, 10))[source]

Opens an interactive window for a specific voltage level.

Parameters:
  • graph (networkx.Graph)

  • level (int)

  • title (Optional[str])

  • figsize (Tuple[int, int])

plot_load_gen_bubbles(grid, layout='kamada_kawai', title='Generation vs Load', show_impedance=False, figsize=(12, 10))[source]

Bubble plot showing generation and load magnitudes. Generators are blue squares, Loads are red circles. Size is proportional to capacity/load. Optionally plots impedance on edges.

Parameters:
  • grid (networkx.Graph)

  • layout (str)

  • title (str)

  • show_impedance (bool)

  • figsize (Tuple[int, int])

plot_subgraphs(grid, layout='kamada_kawai', title='Subgraphs by Voltage Level', show_impedance=False, figsize=(15, 5))[source]

Plots subgraphs for each voltage level side-by-side (max 3 per row).

Parameters:
  • grid (nx.Graph) – The main power grid graph.

  • layout (str) – Layout algorithm to use.

  • title (str) – Main title for the figure.

  • show_impedance (bool) – Whether to color edges by impedance.

  • figsize (Tuple[int, int]) – Base size for the figure (width, height for one row). Height will scale with the number of rows.

class powergrid_synth.core.visualization.MatplotlibDropdown(fig, rect, labels, active=0, on_select=None)[source]

A custom Dropdown widget for Matplotlib, created by combining Buttons.