Skip to content

Commit 4916d76

Browse files
committed
minor improvements to graph plot
1 parent 82c0891 commit 4916d76

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

graphconstructor/visualization/network_plots_nx.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def plot_graph_by_feature(
4242
attribute_type : str
4343
'categorical' or 'continuous'. This will determine the legend used.
4444
pos : dict or None
45-
Optional positions dict; if None, uses nx.spring_layout.
45+
Optional positions dict; if None, uses Kamada Kawai algorithm.
4646
cmap : str
4747
Matplotlib colormap (e.g., 'tab20' for categorical, 'viridis' for continuous).
4848
default_color : str
@@ -122,7 +122,8 @@ def plot_graph_by_feature(
122122
edge_weights = [d.get("weight", 1.0) for _, _, d in nxG.edges(data=True)]
123123
if edge_weights:
124124
max_weight = max(edge_weights)
125-
edge_widths = [0.5 + 5.0 * (w / max_weight) for w in edge_weights]
125+
min_weight = min(edge_weights)
126+
edge_widths = [0.5 + 5.0 * ((w - min_weight) / (max_weight - min_weight)) for w in edge_weights]
126127
edge_colors = [cm.Greys(w / max_weight) for w in edge_weights]
127128
else:
128129
edge_widths = 1.0
@@ -137,7 +138,7 @@ def plot_graph_by_feature(
137138

138139
# Layout
139140
if pos is None:
140-
pos = nx.spring_layout(nxG, seed=42)
141+
pos = nx.kamada_kawai_layout(nxG)
141142

142143
# Figure size
143144
size = (len(node_list) ** 0.5)

0 commit comments

Comments
 (0)