๐Ÿ“Š Plottingยถ

Concepts: Graph representations and plot views Advanced API: ๐Ÿ“Š Plotting

This notebook explains the main plotting functions available for a WindFarmNetwork object.

Inside notebooks, these methods use the vector SVG backends (svgplot/svgpplot) by default. Supplying the ax keyword selects the Matplotlib backends (gplot/pplot), which support Matplotlib figures and subplot layouts.

Import required modulesยถ

[1]:
from optiwindnet.api import WindFarmNetwork, load_repository
[2]:
# Display figures as SVG in Jupyter notebooks
%config InlineBackend.figure_formats = ['svg']

Create a sample networkยถ

Note: load_repository() loads multiple locations from a given path. If no path is given, it loads the built-in locations (more details in ๐Ÿ—‚๏ธ Locations).

[3]:
locations = load_repository()
wfn = WindFarmNetwork(L=locations.anholt, cables=[(2, 1500.0), (5, 1800.0)])

Plot location geometry (L):ยถ

L contains only the raw location data, such as turbine and substation coordinates, borders, and obstacles, without any links or connections between nodes.

As a result, wfn.plot_location() will appear as an edgeless graph, showing only the borders and node elements without network links/edges. Turbines are plotted as circles, and substations as squares.

Use this plot to verify the location data in the WindFarmNetwork() instance before running the optimization.

[4]:
wfn.plot_location()
[4]:
../_images/notebooks_hi14_plotting_11_0.svg

Tip: In a notebook, place wfn on the last line of a cell to plot its current state.

  • Before optimization (no G yet), it renders the location geometry L.

  • If G exists (e.g. after a call to optimize()), it automatically renders G.

[5]:
wfn
[5]:
../_images/notebooks_hi14_plotting_13_0.svg

Optimizeยถ

To plot and visualize the optimized network, an optimization needs to be performed first. Here, the default router (Heuristics-Esau_Williams) is used.

[6]:
res = wfn.optimize()
[7]:
wfn.solution_info()
[7]:
{'router': 'EWRouter', 'capacity': 5, 'method': 'biased_EW', 'iterations': 89}

Plot the Optimized Network Graphยถ

The optimized network graph (G) represents the optimized network with actual routes.

Accordingly, wfn.plot() displays the routes for selected links in the optimized network. The detoured routes are displayed via dashed lines. Detours are the routes created to resolve crossing feeders.

Turbines that belong to the same subtree are assigned the same color. Each cable type is represented with a distinct line thickness (which gets thicker as the cable capacity increases).

[8]:
wfn.plot()
[8]:
../_images/notebooks_hi14_plotting_20_0.svg

Reminder: Place wfn on the last line of a notebook cell to plot the optimized network:

[9]:
wfn
[9]:
../_images/notebooks_hi14_plotting_22_0.svg

Plot in a pre-existing axesยถ

[10]:
import matplotlib.pyplot as plt

plt.rcParams['svg.fonttype'] = 'none'

A plotting method can also target an existing plt.Axes object within a Matplotlib figure:

Tip: Passing the ax keyword to a wfn plotting method selects the Matplotlib backend (gplot/pplot). Use it to combine multiple plots in a standard Matplotlib subplot layout.

Shortcut without imports: Pass ax=None (for example, ax = wfn.plot(ax=None)) to select the Matplotlib backend (gplot/pplot) without importing Matplotlib in the notebook. The plotting method creates a figure and axes internally and returns the resulting plt.Axes object.

[11]:
fig, (ax1, ax2) = plt.subplots(1, 2, facecolor='none', figsize=(8, 4))

wfn.plot_location(ax=ax1)
wfn.plot(ax=ax2, legend=False)
[11]:
<Axes: >
../_images/notebooks_hi14_plotting_26_1.svg

Optional parametersยถ

node_tag (text labels)ยถ

Node tags make it easier to identify each turbine and substation in the plot. The node_tag argument decides what is drawn inside the node symbols:

Value

Effect

True

The node number, assigned in input order: 0 through T - 1 for turbines, and -R through -1 for substations.

'label'

The nodeโ€™s label attribute, as defined in the .yaml or .osm.pbf file, or assigned programmatically.

'load'

The cumulative integer inflow at the node. A turbineโ€™s load includes its own contribution and those feeding into it; a substationโ€™s load sums the contributions of all turbines connected to it.

'attribute_name'

The value of any other node attribute.

With the default contribution of one per turbine, these loads count turbines. For unequal ratings and labels in power units, see Interpreting results and the Mixed turbine power example.

Default symbol sizes suit tags of up to three characters; longer tags may not fit.

[12]:
wfn.plot(node_tag=True)
[12]:
../_images/notebooks_hi14_plotting_30_0.svg

Labels in location data files

Labels come from the location data file itself: see OptiWindNet YAML and OpenStreetMap PBF for how they are declared in each format. They can also be assigned programmatically, as below.

[13]:
wfn.plot(node_tag='label', infobox=False, legend=True)
[13]:
../_images/notebooks_hi14_plotting_32_0.svg
[14]:
wfn.L.nodes[0]['example_label'] = 'T0'
[15]:
wfn.plot_location(node_tag='example_label')
[15]:
../_images/notebooks_hi14_plotting_34_0.svg

The nodes can also be tagged with the load they export towards the substation:

[16]:
wfn.plot(node_tag='load')
[16]:
../_images/notebooks_hi14_plotting_36_0.svg

dark (color theme)ยถ

The theme is matched to the operating systemโ€™s by default, through the darkdetect package โ€” note that this detects the system theme, not JupyterLabโ€™s, so the two can disagree. Set dark=True or dark=False to decide explicitly.

[17]:
wfn.plot(dark=False)
[17]:
../_images/notebooks_hi14_plotting_39_0.svg

landscape_angle (rotation)ยถ

Each location included in OptiWindNet has a graph attribute called landscape_angle.

[18]:
wfn.L.graph['landscape_angle']
[18]:
81.8

This is the angle by which to rotate the site so as to orient the widest dimension horizontally. Pass landscape=False to orient the location with north up instead.

[19]:
wfn.plot(landscape=False)
[19]:
../_images/notebooks_hi14_plotting_44_0.svg

Plotting Auxiliary Graphsยถ

Of the five plot methods, wfn.plot_location() and wfn.plot() have been presented above.

The remaining three show the auxiliary graphs navigation_mesh, available_links and selected_links, which are relevant mainly for debugging and development. The graph representations and plot views describe what each view means and the graph underlying it.