@@ -55,19 +55,21 @@ class NetworkArtist(PlotterArtist, NetworkArtist):
5555
5656 """
5757
58- def __init__ (self ,
59- network : Network ,
60- nodes : Optional [List [int ]] = None ,
61- edges : Optional [List [int ]] = None ,
62- nodecolor : Color = (1.0 , 1.0 , 1.0 ),
63- edgecolor : Color = (0.0 , 0.0 , 0.0 ),
64- edgewidth : float = 1.0 ,
65- show_nodes : bool = True ,
66- show_edges : bool = True ,
67- nodesize : int = 5 ,
68- sizepolicy : Literal ['relative' , 'absolute' ] = 'relative' ,
69- zorder : int = 1000 ,
70- ** kwargs ):
58+ def __init__ (
59+ self ,
60+ network : Network ,
61+ nodes : Optional [List [int ]] = None ,
62+ edges : Optional [List [int ]] = None ,
63+ nodecolor : Color = (1.0 , 1.0 , 1.0 ),
64+ edgecolor : Color = (0.0 , 0.0 , 0.0 ),
65+ edgewidth : float = 1.0 ,
66+ show_nodes : bool = True ,
67+ show_edges : bool = True ,
68+ nodesize : int = 5 ,
69+ sizepolicy : Literal ["relative" , "absolute" ] = "relative" ,
70+ zorder : int = 1000 ,
71+ ** kwargs ,
72+ ):
7173
7274 super ().__init__ (network = network , ** kwargs )
7375
@@ -101,21 +103,31 @@ def item(self, item: Network):
101103
102104 @property
103105 def data (self ) -> List [List [float ]]:
104- return self .network .nodes_attributes ('xy' )
106+ return self .network .nodes_attributes ("xy" )
105107
106108 @property
107109 def node_size (self ):
108110 if not self ._node_size :
109- factor = self .plotter .dpi if self .sizepolicy == 'absolute' else self .network .number_of_nodes ()
111+ factor = (
112+ self .plotter .dpi
113+ if self .sizepolicy == "absolute"
114+ else self .network .number_of_nodes ()
115+ )
110116 size = self .default_nodesize / factor
111117 self ._node_size = {node : size for node in self .network .nodes ()}
112118 return self ._node_size
113119
114120 @node_size .setter
115121 def node_size (self , nodesize ):
116- factor = self .plotter .dpi if self .sizepolicy == 'absolute' else self .network .number_of_nodes ()
122+ factor = (
123+ self .plotter .dpi
124+ if self .sizepolicy == "absolute"
125+ else self .network .number_of_nodes ()
126+ )
117127 if isinstance (nodesize , dict ):
118- self .node_size .update ({node : size / factor for node , size in nodesize .items ()})
128+ self .node_size .update (
129+ {node : size / factor for node , size in nodesize .items ()}
130+ )
119131 elif isinstance (nodesize , (int , float )):
120132 self ._node_size = {node : nodesize / factor for node in self .network .nodes ()}
121133
@@ -178,9 +190,11 @@ def draw(self,
178190 if self .show_edges :
179191 self .draw_edges (edges = edges , color = edgecolor )
180192
181- def draw_nodes (self ,
182- nodes : Optional [List [int ]] = None ,
183- color : Optional [Union [str , Color , List [Color ], Dict [int , Color ]]] = None ) -> None :
193+ def draw_nodes (
194+ self ,
195+ nodes : Optional [List [int ]] = None ,
196+ color : Optional [Union [str , Color , List [Color ], Dict [int , Color ]]] = None ,
197+ ) -> None :
184198 """Draw a selection of nodes.
185199
186200 Parameters
@@ -215,17 +229,16 @@ def draw_nodes(self,
215229 circles .append (circle )
216230
217231 collection = PatchCollection (
218- circles ,
219- match_original = True ,
220- zorder = self .zorder_nodes ,
221- alpha = 1.0
232+ circles , match_original = True , zorder = self .zorder_nodes , alpha = 1.0
222233 )
223234 self .plotter .axes .add_collection (collection )
224235 self ._nodecollection = collection
225236
226- def draw_edges (self ,
227- edges : Optional [Tuple [int , int ]] = None ,
228- color : Optional [Union [str , Color , List [Color ], Dict [int , Color ]]] = None ) -> None :
237+ def draw_edges (
238+ self ,
239+ edges : Optional [Tuple [int , int ]] = None ,
240+ color : Optional [Union [str , Color , List [Color ], Dict [int , Color ]]] = None ,
241+ ) -> None :
229242 """Draw a selection of edges.
230243
231244 Parameters
@@ -259,9 +272,9 @@ def draw_edges(self,
259272 lines ,
260273 linewidths = widths ,
261274 colors = colors ,
262- linestyle = ' solid' ,
275+ linestyle = " solid" ,
263276 alpha = 1.0 ,
264- zorder = self .zorder_edges
277+ zorder = self .zorder_edges ,
265278 )
266279 self .plotter .axes .add_collection (collection )
267280 self ._edgecollection = collection
@@ -298,13 +311,15 @@ def draw_nodelabels(self, text: Optional[Dict[int, str]] = None) -> None:
298311
299312 x , y = self .node_xyz [node ][:2 ]
300313 artist = self .plotter .axes .text (
301- x , y ,
302- f'{ text } ' ,
314+ x ,
315+ y ,
316+ f"{ text } " ,
303317 fontsize = self .plotter .fontsize ,
304- family = 'monospace' ,
305- ha = 'center' , va = 'center' ,
318+ family = "monospace" ,
319+ ha = "center" ,
320+ va = "center" ,
306321 zorder = 10000 ,
307- color = color
322+ color = color ,
308323 )
309324 labels .append (artist )
310325
@@ -343,13 +358,21 @@ def draw_edgelabels(self, text: Optional[Dict[int, str]] = None) -> None:
343358 y = 0.5 * (y0 + y1 )
344359
345360 artist = self .plotter .axes .text (
346- x , y , f'{ text } ' ,
361+ x ,
362+ y ,
363+ f"{ text } " ,
347364 fontsize = self .plotter .fontsize ,
348- family = 'monospace' ,
349- ha = 'center' , va = 'center' ,
365+ family = "monospace" ,
366+ ha = "center" ,
367+ va = "center" ,
350368 zorder = 10000 ,
351369 color = (0 , 0 , 0 ),
352- bbox = dict (boxstyle = 'round, pad=0.3' , facecolor = (1 , 1 , 1 ), edgecolor = None , linewidth = 0 )
370+ bbox = dict (
371+ boxstyle = "round, pad=0.3" ,
372+ facecolor = (1 , 1 , 1 ),
373+ edgecolor = None ,
374+ linewidth = 0 ,
375+ ),
353376 )
354377 labels .append (artist )
355378
0 commit comments