@@ -48,9 +48,9 @@ def plot_degree_distribution(
4848 - When `x_scale` or `y_scale` is "log", any k=0 or p(k)=0 entries are removed
4949 to avoid invalid values on a log axis.
5050 """
51- degrees = graph .degree ()
51+ degrees = graph .degree (ignore_weights = True )
5252 if degrees .ndim != 1 :
53- raise ValueError ("graph.degree() must return a 1-D array of degrees." )
53+ raise ValueError ("graph.degree(ignore_weights=True ) must return a 1-D array of degrees." )
5454 if degrees .size == 0 :
5555 # Create empty plot but still return fig/ax for consistency
5656 if ax is None :
@@ -77,8 +77,7 @@ def plot_degree_distribution(
7777 raise ValueError ("Degrees must be integers for degree distributions." )
7878
7979 counts = np .bincount (degrees ) # index = k, value = count(k)
80- ks = np .nonzero (counts )[0 ] # degrees that actually appear
81- freqs = counts [ks ].astype (float )
80+ freqs = counts .astype (float )
8281
8382 if normalize :
8483 total = freqs .sum ()
@@ -90,13 +89,10 @@ def plot_degree_distribution(
9089
9190 # Handle zero-degree inclusion/exclusion
9291 if not include_zero_degree or x_scale == "log" :
93- mask = ks > 0
94- ks , pk = ks [mask ], pk [mask ]
95-
96- # On log y, remove zero probabilities (shouldn't occur if computed as above)
97- if y_scale == "log" :
98- nz = pk > 0
99- ks , pk = ks [nz ], pk [nz ]
92+ ks = np .nonzero (counts )[0 ]
93+ pk = pk [ks ]
94+ else :
95+ ks = np .arange (len (counts ))
10096
10197 # Prepare axes
10298 if ax is None :
@@ -170,7 +166,7 @@ def plot_degree_distributions_grid(
170166 if n == 0 :
171167 raise ValueError ("`graphs` must contain at least one graph." )
172168
173- nrows = np .ceil (n / ncols )
169+ nrows = int ( np .ceil (n / ncols ) )
174170 if figsize is None :
175171 # heuristic: wider for more columns, taller for more rows
176172 figsize = (4 * ncols , 3.2 * nrows )
0 commit comments