File size: 2,988 Bytes
5543795
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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

from __future__ import annotations

from typing import Dict

import networkx as nx
import numpy as np
import plotly.graph_objects as go


def make_overlay_figure(
    G_ideal: nx.Graph,
    pos_ideal: Dict[int, np.ndarray],
    G_real: nx.Graph,
    pos_real: Dict[int, np.ndarray],
    boundary_nodes,
    show_ideal: bool = True,
) -> go.Figure:
    """
    3D-Overlay von IDEAL- und REAL-Graph.
    """
    boundary_nodes = set(boundary_nodes)

    fig = go.Figure()

    if show_ideal:
        # IDEAL-Kanten
        x_e = []
        y_e = []
        z_e = []
        for u, v in G_ideal.edges:
            p0 = pos_ideal[u]
            p1 = pos_ideal[v]
            x_e += [p0[0], p1[0], None]
            y_e += [p0[1], p1[1], None]
            z_e += [p0[2], p1[2], None]

        fig.add_trace(
            go.Scatter3d(
                x=x_e,
                y=y_e,
                z=z_e,
                mode="lines",
                name="IDEAL",
                line=dict(width=2),
                hoverinfo="skip",
            )
        )

    # REAL-Kanten
    x_e = []
    y_e = []
    z_e = []
    for u, v in G_real.edges:
        p0 = pos_real[u]
        p1 = pos_real[v]
        x_e += [p0[0], p1[0], None]
        y_e += [p0[1], p1[1], None]
        z_e += [p0[2], p1[2], None]

    fig.add_trace(
        go.Scatter3d(
            x=x_e,
            y=y_e,
            z=z_e,
            mode="lines",
            name="REAL",
            line=dict(width=2),
            hoverinfo="skip",
        )
    )

    # Innere REAL-Knoten
    x_i = []
    y_i = []
    z_i = []
    text_i = []
    for n, p in pos_real.items():
        if n in boundary_nodes:
            continue
        x_i.append(p[0])
        y_i.append(p[1])
        z_i.append(p[2])
        text_i.append(str(n))

    fig.add_trace(
        go.Scatter3d(
            x=x_i,
            y=y_i,
            z=z_i,
            mode="markers",
            name="innere Knoten (REAL)",
            marker=dict(size=4),
            text=text_i,
            hovertemplate="Knoten-ID=%{text}<extra></extra>",
        )
    )

    # Randknoten (REAL)
    x_b = []
    y_b = []
    z_b = []
    text_b = []
    for n in boundary_nodes:
        p = pos_real[n]
        x_b.append(p[0])
        y_b.append(p[1])
        z_b.append(p[2])
        text_b.append(str(n))

    fig.add_trace(
        go.Scatter3d(
            x=x_b,
            y=y_b,
            z=z_b,
            mode="markers",
            name="äußerste Randknoten",
            marker=dict(size=6, symbol="diamond"),
            text=text_b,
            hovertemplate="Knoten-ID=%{text}<extra></extra>",
        )
    )

    fig.update_layout(
        scene=dict(
            xaxis_title="x",
            yaxis_title="y",
            zaxis_title="z",
            aspectmode="data",
        ),
        legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="left", x=0.0),
        margin=dict(l=0, r=0, b=0, t=30),
    )
    return fig