@@ -105,12 +105,67 @@ def draw_self_loop(
105
105
return axes
106
106
107
107
108
+ def draw_smaller_self_loop (
109
+ axes : Axes ,
110
+ posx : float ,
111
+ posy : float ,
112
+ size : float ,
113
+ rad : float = 0.4 ,
114
+ offset : float = 0.01 ,
115
+ mutation_scale : int = 20 ,
116
+ onearrow : bool = True ,
117
+ ) -> Axes :
118
+
119
+ all_arrows_pos = [
120
+ (posx , posy , posx , posy - size , rad ),
121
+ (posx - offset , posy - size + offset , posx + size , posy - size , rad ),
122
+ (posx + size - offset , posy - size - offset , posx + size , posy , rad ),
123
+ ]
124
+
125
+ all_arrows_pos = [
126
+ (posx , posy , posx , posy - size , rad ),
127
+ (
128
+ posx - offset ,
129
+ posy - size + offset ,
130
+ posx + size + offset ,
131
+ posy - size + offset ,
132
+ rad ,
133
+ ),
134
+ (posx + size , posy - size , posx + size , posy , rad ),
135
+ ]
136
+
137
+ for pos_i , arr_pos in enumerate (all_arrows_pos ):
138
+ px , py , sx , sy , rad = arr_pos
139
+
140
+ style = "-"
141
+ if onearrow :
142
+ if pos_i == len (all_arrows_pos ) - 1 :
143
+ style = "-|>"
144
+ elif pos_i % 2 :
145
+ style = "-|>"
146
+
147
+ arrow = FancyArrowPatch (
148
+ (px , py ),
149
+ (sx , sy ),
150
+ arrowstyle = style ,
151
+ mutation_scale = mutation_scale ,
152
+ linewidth = 2 ,
153
+ color = "k" ,
154
+ connectionstyle = f"arc3,rad={ rad } " ,
155
+ )
156
+
157
+ axes .add_patch (arrow )
158
+
159
+ return axes
160
+
161
+
108
162
def plot_community_scheme (
109
163
ax : Optional [Axes ] = None ,
110
164
use_cmap : bool = True ,
111
165
title_letter : str = "" ,
112
166
fontscale : float = 1.2 ,
113
167
com_names : Optional [np .ndarray ] = None ,
168
+ com_names_yoffset : float = 0 ,
114
169
x_names : [str , str ] = ["Sending 1" , "Sending 2" ],
115
170
y_names : [str , str ] = ["Receiving 1" , "Receiving 2" ],
116
171
arrow_colors : Optional [np .ndarray ] = None ,
@@ -186,7 +241,8 @@ def plot_community_scheme(
186
241
187
242
for pos , com_name in zip (xy_pos , com_names ):
188
243
ax .text (
189
- * pos ,
244
+ pos [0 ],
245
+ pos [1 ] + com_names_yoffset ,
190
246
com_name ,
191
247
fontsize = 24 * fontscale ,
192
248
fontweight = "bold" ,
@@ -386,10 +442,13 @@ def plot_spectrum(
386
442
markeredgecolor = "k" ,
387
443
markeredgewidth = 4 ,
388
444
)
445
+ angle = (V .T @ U )[vector_id , vector_id ]
389
446
axes [0 ].text (
390
447
x_id + 1 ,
391
448
S [vector_id ],
392
- f"$\\ mu_{{{ x_id + 1 } }}={ S [vector_id ]:2.2f} , R^2={ r_squared :1.2f} $" ,
449
+ # f"$\\mu_{{{x_id+1}}}={S[vector_id]:2.2f}, R^2={r_squared:1.2f}$",
450
+ # f"$\\mu_{{{x_id+1}}}={S[vector_id]:2.2f},\,\\mathbf{{v}}_{{{vector_id+1}}}^{{T}}\\mathbf{{u}}_{{{vector_id+1}}}={angle:1.2f}$",
451
+ f"$\\ mu_{{{ x_id + 1 } }}={ S [vector_id ]:2.2f} $\n $\\ mathbf{{v}}_{{{ vector_id + 1 } }}^{{T}}\\ mathbf{{u}}_{{{ vector_id + 1 } }}={ angle :1.2f} $" ,
393
452
# f"$s_{{{x_id}}}={S[vector_id]:2.2f}, R^2={r_squared:1.2f}$",
394
453
fontsize = 18 * fontscale ,
395
454
ha = "left" ,
@@ -511,6 +570,7 @@ def plot_graph_embedding(
511
570
ax : Optional [Axes ] = None ,
512
571
use_cmap : bool = True ,
513
572
cmap : str = "plasma" ,
573
+ static_color : str = "tab:blue" ,
514
574
write_label : bool = False ,
515
575
write_var : bool = False ,
516
576
label_lw : int = 3 ,
@@ -556,7 +616,7 @@ def plot_graph_embedding(
556
616
except ValueError :
557
617
colors = [cmap ] * n_nodes
558
618
else :
559
- colors = "tab:blue"
619
+ colors = static_color
560
620
561
621
ax .scatter (
562
622
U [:, vector_id ],
@@ -576,6 +636,29 @@ def plot_graph_embedding(
576
636
f"$R^2={ expl_var :1.3f} $" ,
577
637
transform = ax .transAxes ,
578
638
fontsize = 16 * fontscale ,
639
+ path_effects = [
640
+ withStroke (
641
+ linewidth = label_lw ,
642
+ foreground = "w" ,
643
+ alpha = 0.8 ,
644
+ )
645
+ ],
646
+ )
647
+
648
+ angle = (V .T @ U )[vector_id , vector_id ]
649
+ ax .text (
650
+ 0.05 ,
651
+ 0.85 ,
652
+ f"$\\ mathbf{{v}}^T\\ mathbf{{u}}={ angle :1.2f} $" ,
653
+ transform = ax .transAxes ,
654
+ fontsize = 16 * fontscale ,
655
+ path_effects = [
656
+ withStroke (
657
+ linewidth = label_lw ,
658
+ foreground = "w" ,
659
+ alpha = 0.8 ,
660
+ )
661
+ ],
579
662
)
580
663
581
664
if write_label :
@@ -756,17 +839,20 @@ def plot_all_bicommunity(
756
839
scatter_only = False ,
757
840
titles = None ,
758
841
nrows = 1 ,
842
+ ncols = None ,
759
843
draw_legend = True ,
760
844
legend_on_ax = False ,
761
845
cmap = None ,
762
846
gspec_wspace = 0 ,
763
847
gspec_hspace = 0.05 ,
764
848
** kwargs ,
765
849
):
850
+ if ncols is None :
851
+ ncols = len (send_com ) // nrows + (len (send_com ) % nrows )
766
852
767
853
com_gs = GridSpecFromSubplotSpec (
768
854
nrows = nrows ,
769
- ncols = len ( send_com ) // nrows + ( len ( send_com ) % nrows ) ,
855
+ ncols = ncols ,
770
856
# ncols=len(send_com) // nrows,
771
857
subplot_spec = axes ,
772
858
wspace = gspec_wspace ,
@@ -782,7 +868,10 @@ def plot_all_bicommunity(
782
868
U , _ , Vh = dgsp .sorted_SVD (dgsp .modularity_matrix (adjacency ))
783
869
V = Vh .T
784
870
785
- graph_pos = {i : (U [i , 0 ], V [i , 0 ]) for i , _ in enumerate (adjacency )}
871
+ if np .allclose (adjacency , adjacency .T ):
872
+ graph_pos = {i : (U [i , 0 ], V [i , 1 ]) for i , _ in enumerate (adjacency )}
873
+ else :
874
+ graph_pos = {i : (U [i , 0 ], V [i , 0 ]) for i , _ in enumerate (adjacency )}
786
875
else :
787
876
graph_pos = nx .spring_layout (nx .DiGraph (adjacency ))
788
877
0 commit comments