๐ 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]:
Tip: In a notebook, place
wfnon the last line of a cell to plot its current state.
Before optimization (no
Gyet), it renders the location geometryL.If
Gexists (e.g. after a call to optimize()), it automatically rendersG.
[5]:
wfn
[5]:
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]:
Reminder: Place
wfnon the last line of a notebook cell to plot the optimized network:
[9]:
wfn
[9]:
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:
[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: >
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 |
|---|---|
|
The node number, assigned in input order: |
|
The nodeโs |
|
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. |
|
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]:
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]:
[14]:
wfn.L.nodes[0]['example_label'] = 'T0'
[15]:
wfn.plot_location(node_tag='example_label')
[15]:
The nodes can also be tagged with the load they export towards the substation:
[16]:
wfn.plot(node_tag='load')
[16]:
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]:
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]:
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.
Available Linksยถ
The available-links graph wfn.A shows the candidate connections between turbines. Direct Delaunay links are solid and diagonal alternatives are dashed; colors distinguish links obstructed by boundaries or obstacles.
The optimizer also considers substation-to-turbine feeders. These are omitted from this view because drawing every possible feeder would obscure the candidate connections between turbines.
[21]:
wfn.plot_available_links()
[21]:
Selected Linksยถ
wfn.plot_selected_links() displays the selected turbine connections and substation feeders before final routing. Selected links already follow boundary contours where needed, but feeder detours that avoid crossings have not yet been applied. Use wfn.plot() to see the completed cable routes.
[22]:
wfn.plot_selected_links()
[22]: