plot
PlotEngine
PlotEngine(engine: Union[BalanceEngine, PositionEngine])
Bases: Observer
PlotEngine renders power-line sections on Plotly figures.
It accepts either a BalanceEngine
or an already-constructed PositionEngine.
When a BalanceEngine is passed, a PositionEngine is created
automatically and exposed via position_engine.
Reactivity is preserved through a two-hop observer chain:
1 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Union[BalanceEngine, PositionEngine]
|
A |
required |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Source code in src/mechaphlowers/plotting/plot.py
431 432 433 434 435 436 437 438 439 440 441 442 443 | |
span_names
property
Names of the spans, each being the concatenation of the two adjacent support names.
For supports ["A", "B", "C"] this returns ["A-B", "B-C"].
support_names
property
Names of the supports as defined in the section array.
add_obstacle_array
add_obstacle_array(obstacle_array: ObstacleArray) -> None
Delegate to PositionEngine.add_obstacle_array.
Source code in src/mechaphlowers/plotting/plot.py
517 518 519 | |
get_insulators_points
get_insulators_points() -> ndarray
Delegate to PositionEngine.get_insulators_points.
Source code in src/mechaphlowers/plotting/plot.py
531 532 533 | |
get_loads_coords
Delegate to PositionEngine.get_loads_coords.
Source code in src/mechaphlowers/plotting/plot.py
548 549 550 551 552 | |
get_obstacles_points
get_obstacles_points() -> ndarray
Delegate to PositionEngine.get_obstacles_points.
Source code in src/mechaphlowers/plotting/plot.py
535 536 537 | |
get_points_for_plot
Delegate to PositionEngine.get_points_for_plot.
Source code in src/mechaphlowers/plotting/plot.py
554 555 556 557 558 | |
get_spans_points
get_spans_points(
frame: Literal['section', 'localsection', 'cable'],
) -> ndarray
Delegate to PositionEngine.get_spans_points.
Source code in src/mechaphlowers/plotting/plot.py
521 522 523 524 525 | |
get_supports_points
get_supports_points() -> ndarray
Delegate to PositionEngine.get_supports_points.
Source code in src/mechaphlowers/plotting/plot.py
527 528 529 | |
initialize_engine
initialize_engine(balance_engine: BalanceEngine) -> None
Delegate to PositionEngine.initialize_engine.
Source code in src/mechaphlowers/plotting/plot.py
509 510 511 | |
obstacles_dict
obstacles_dict(project=False, frame_index=0) -> dict
Returns a dictionary storing object coordinates.
Key is object name, value is coordinates of object.
Format: {'obs_0': [[x0, y0, z0], [x1, y1, z1], ...]}
Source code in src/mechaphlowers/plotting/plot.py
539 540 541 542 543 544 545 546 | |
point_distance
point_distance(
obstacle_name: str,
point_index: int,
*,
fig: Figure | None = None,
) -> DistanceResult
Compute the distance from point to a span, with optional plotting.
Delegates the geometric computation to
PositionEngine.point_distance and, when fig is provided,
plots the result on the figure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Obstacle name to get the distances of. |
required |
|
int
|
point_index of the selected obstacle. |
required |
|
Figure | None
|
Optional Plotly figure. When supplied, the geometry is rendered on it. |
None
|
Returns:
| Type | Description |
|---|---|
DistanceResult
|
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Source code in src/mechaphlowers/plotting/plot.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 | |
point_relative_to_absolute
point_relative_to_absolute(
span_index: int, point_relative: ndarray
) -> ndarray
Delegate to PositionEngine.point_relative_to_absolute.
Source code in src/mechaphlowers/plotting/plot.py
788 789 790 791 792 793 794 | |
preview_line2d
preview_line2d(
fig: Figure,
view: Literal['profile', 'line'] = 'profile',
frame_index: int = 0,
mode: Literal['main', 'background'] = 'main',
name_addendum: str = '',
cable_name: str | None = None,
cable_name_addendum: str | None = None,
support_name: str | None = None,
support_name_addendum: str | None = None,
insulator_name: str | None = None,
insulator_name_addendum: str | None = None,
) -> None
Plot 2D of power lines sections
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Figure
|
plotly figure where new traces has to be added |
required |
|
Literal['profile', 'line']
|
profile or line view. Defaults to "profile". |
'profile'
|
|
int
|
Index of the frame for projection. Defaults to 0. |
0
|
|
Literal['main', 'background']
|
Rendering mode. Defaults to "main". |
'main'
|
|
str
|
String appended to all trace names. Defaults to "". |
''
|
|
str | None
|
Full override for the cable trace legend label. |
None
|
|
str
|
Addendum for the cable trace name (overrides name_addendum). |
None
|
|
str | None
|
Full override for the support trace legend label. |
None
|
|
str
|
Addendum for the support trace name (overrides name_addendum). |
None
|
|
str | None
|
Full override for the insulator trace legend label. |
None
|
|
str
|
Addendum for the insulator trace name (overrides name_addendum). |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
view value is invalid |
Source code in src/mechaphlowers/plotting/plot.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | |
preview_line3d
preview_line3d(
fig: Figure,
view: Literal['full', 'analysis'] = 'full',
mode: Literal['main', 'background'] = 'main',
aspect_ratio: dict[str, float] | None = None,
name_addendum: str = '',
cable_name: str | None = None,
cable_name_addendum: str | None = None,
support_name: str | None = None,
support_name_addendum: str | None = None,
insulator_name: str | None = None,
insulator_name_addendum: str | None = None,
) -> None
Plot 3D of power lines sections
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Figure
|
plotly figure where new traces has to be added |
required |
|
Literal['full', 'analysis']
|
full for scale respect view, analysis for compact view. Defaults to "full". |
'full'
|
|
Literal['main', 'background']
|
Style mode for the traces. Defaults to "main". |
'main'
|
|
dict[str, float] | None
|
Custom aspect ratio dictionary with keys 'x', 'y', 'z'. When provided, overrides the layout aspect ratio. Can be computed using compute_aspect_ratio(). Defaults to None. |
None
|
|
str
|
String appended to all trace names. Defaults to "". |
''
|
|
str | None
|
Full override for the cable trace legend label. |
None
|
|
str
|
Addendum for the cable trace name (overrides name_addendum). |
None
|
|
str | None
|
Full override for the support trace legend label. |
None
|
|
str
|
Addendum for the support trace name (overrides name_addendum). |
None
|
|
str | None
|
Full override for the insulator trace legend label. |
None
|
|
str
|
Addendum for the insulator trace name (overrides name_addendum). |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
view is not an expected value |
Source code in src/mechaphlowers/plotting/plot.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 | |
reset
reset(balance_engine: BalanceEngine) -> None
Delegate to PositionEngine.reset.
Source code in src/mechaphlowers/plotting/plot.py
513 514 515 | |
update
update(notifier: Notifier) -> None
Receive notification from PositionEngine.
The PositionEngine has already refreshed all coordinates before
calling this method, so no additional state update is required here.
Source code in src/mechaphlowers/plotting/plot.py
447 448 449 450 451 452 453 | |
figure_factory
figure_factory(context=Literal['std', 'blank']) -> Figure
create_figure creates a plotly figure
Returns:
| Type | Description |
|---|---|
Figure
|
go.Figure: plotly figure |
Source code in src/mechaphlowers/plotting/plot.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
plot_support_shape
plot_support_shape(
fig: Figure,
support_shape: SupportShape,
structure_name: str | None = None,
points_name: str | None = None,
) -> None
plot_support_shape enables to plot the support shape on a plotly figure
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Figure
|
plotly figure |
required |
|
SupportShape
|
SupportShape object to plot |
required |
|
str | None
|
Legend label for the structure trace. Defaults to the support shape name. |
None
|
|
str | None
|
Legend label for the attachment points trace. Defaults to "Attachment points". |
None
|
Source code in src/mechaphlowers/plotting/plot.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
set_layout
set_layout
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Figure
|
plotly figure where layout has to be updated |
required |
|
bool
|
Automatic layout based on data (scale respect). False means manual with an aspectratio of x=1, y=.5, z=.5. Only used when aspect_ratio is None. Defaults to True. |
True
|
|
dict[str, float] | None
|
Custom aspect ratio dictionary with keys 'x', 'y', 'z'. When provided, forces aspectmode to 'manual' and uses these values. When None, behavior is controlled by the auto parameter. Defaults to None. |
None
|
Examples:
1 2 3 4 5 6 7 | |
Source code in src/mechaphlowers/plotting/plot.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
utils
Plotting utility functions for data visualization and layout configuration.
compute_aspect_ratio
compute_aspect_ratio(
*points_objects: Points | SparsePoints,
x_scale: float = 1.0,
y_scale: float = 1.0,
z_scale: float = 1.0,
) -> dict[str, float]
Compute an aspect ratio dictionary for Plotly 3D plots based on data coordinates.
This function analyzes the spatial extent of multiple Points objects (typically spans, supports, and insulators from a power line section) and computes normalized aspect ratios that respect the actual data ranges while allowing custom scaling per axis.
The algorithm:
- Concatenates all points from all Points objects into a single array
- Computes min/max for each axis (x, y, z)
- Calculates the range (max - min) for each axis
- Normalizes each range by dividing by the maximum of all three ranges
- Applies custom scaling factors to each normalized ratio
- Returns a dict suitable for Plotly's aspectratio parameter
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Points | SparsePoints
|
Variable number of Points objects to analyze. Typically these come from PlotEngine.get_points_for_plot() which returns (spans, supports, insulators). |
()
|
|
float
|
Scaling factor for the x-axis ratio. Defaults to 1.0. |
1.0
|
|
float
|
Scaling factor for the y-axis ratio. Defaults to 1.0. |
1.0
|
|
float
|
Scaling factor for the z-axis ratio. Defaults to 1.0. Common use case: z_scale=10 to exaggerate altitude dimension for better visibility. |
1.0
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
dict[str, float]: A dictionary with keys 'x', 'y', 'z' containing the normalized aspect ratios scaled by the provided factors. Each value is a float in the range [0.0001, scale_factor] approximately (exact range depends on data). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no Points objects are provided, or if all points are NaN. |
ValueError
|
If scale factors are not positive. |
Examples:
1 2 3 4 5 6 7 8 9 10 11 | |
See Also
PlotEngine.preview_line3d: Plotting method that can use this function. Points: The coordinate class used to represent geometric data.
Source code in src/mechaphlowers/plotting/utils.py
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |