Spaces:
Sleeping
Sleeping
Download src/modules/visualization.py from Sierpinksi-Project/NGF_on_Fractale: direct link, hf CLI and curl.
- Browser
- Download file 2.99 kB
-
https://huggingface.co/spaces/Sierpinksi-Project/NGF_on_Fractale/resolve/main/src/modules/visualization.py
- Command line
-
hf download hf://spaces/Sierpinksi-Project/NGF_on_Fractale/src/modules/visualization.py
-
curl -L -o visualization.py https://huggingface.co/spaces/Sierpinksi-Project/NGF_on_Fractale/resolve/main/src/modules/visualization.py
2.99 kB
| 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 | |