Plotting
Overview
The plotting module provides tools to visualize power line sections in 2D and 3D using Plotly.
The main entry point is the PlotEngine class, which is built from a BalanceEngine and provides methods to generate 3D and 2D views of the line, including cables, supports and insulators.
PlotEngine
Creating a PlotEngine
A PlotEngine is created from a BalanceEngine using the builder_from_balance_engine factory method:
1 2 3 4 5 | |
Important
The BalanceEngine must have been solved (adjustment and change of state) before creating a PlotEngine.
Reactive updates
If the BalanceEngine attributes change after creating the PlotEngine (e.g., new weather conditions), you can regenerate the plot engine:
1 2 | |
Getting points data
The get_points_for_plot method returns the computed coordinates of all plotted objects as three Points objects (spans, supports, insulators):
1 | |
These Points objects can be used for custom analysis, or passed to compute_aspect_ratio (see below).
For 2D projections, set project=True and specify a frame_index:
1 2 3 | |
3D visualization
preview_line3d
Use preview_line3d to add 3D traces (cables, supports, insulators) to a Plotly figure:
1 2 3 | |
The view argument controls the layout mode:
"full"(default): uses Plotly'saspectmode="data"to respect real-world scale."analysis": usesaspectmode="manual"with a compact view, better for inspecting shapes.
1 2 3 | |
Overlaying multiple states
You can overlay multiple weather or load states on the same figure by calling preview_line3d several times. Use the mode argument to visually distinguish them:
1 2 3 4 5 6 7 8 9 10 11 | |
"main"(default): standard solid traces."background": dotted traces for secondary/reference states.
2D visualization
preview_line2d
Use preview_line2d to add 2D traces to a Plotly figure. The 3D coordinates are projected into a support-local frame.
Two views are available:
"profile"(default): X axis is along the span direction, Y axis is altitude. The Y axis auto-ranges to show all data."line": X axis is the transverse direction (perpendicular to span), Y axis is altitude. The scale is anchored to preserve real proportions.
1 2 3 4 5 6 7 | |
The frame_index argument selects which support is used as the origin for the 2D projection. It must be between \(0\) and \(N_{supports} - 1\).
Aspect ratio and layout
The problem
In 3D power line plots, the horizontal extent (X/Y) of a section is typically much larger than the vertical extent (Z). Plotly's default aspectmode="data" preserves real-world proportions, but the altitude differences may become hard to see.
The compute_aspect_ratio function solves this by computing the true data ranges and allowing you to exaggerate specific axes.
compute_aspect_ratio
This standalone function takes the Points objects from get_points_for_plot and computes a Plotly-compatible aspect ratio dictionary:
1 2 3 4 5 6 7 | |
Use scale factors to exaggerate specific axes. A common use case is z_scale to amplify altitude:
1 2 3 4 5 6 | |
Note
The function normalizes each axis range by the maximum range across all three axes, then multiplies by the corresponding scale factor. With default scales (\(1.0\)), the largest axis always has ratio \(1.0\).
Injecting aspect ratio into preview_line3d
Pass the computed aspect ratio directly to preview_line3d:
1 2 3 | |
When aspect_ratio is provided, the layout is set to aspectmode="manual" with the given values, regardless of the view argument.
Using set_layout directly
The set_layout function controls the 3D scene layout (axis labels, aspect ratio, camera). It is called internally by preview_line3d, but you can also use it directly for finer control:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Important
When aspect_ratio is provided, the auto parameter is ignored for the aspect ratio. The layout always uses aspectmode="manual" with the provided values.
Complete example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |