K iڝJdZddlZddlZddlmZddlZgdZ ddZ ddZ ddZ ddZ dd Z Gd d Z dd Z dd Z ddZdZdZdZdZdZdZddZdZdZd dZy)!a ********** Matplotlib ********** Draw networks with matplotlib. Examples -------- >>> G = nx.complete_graph(5) >>> nx.draw(G) See Also -------- - :doc:`matplotlib ` - :func:`matplotlib.pyplot.scatter` - :obj:`matplotlib.patches.FancyArrowPatch` N)Number)displayapply_matplotlib_colorsdraw draw_networkxdraw_networkx_nodesdraw_networkx_edgesdraw_networkx_labelsdraw_networkx_edge_labelsdraw_bipartite draw_circulardraw_kamada_kawai draw_random draw_spectral draw_spring draw_planar draw_shelldraw_forceatlas2c ddl}|r|j}n3|jr|jd}n|j}||/|D cgc] } || | } } | t | }| t | }|j j|j||fd} |rKtj||jD cic]} | | |j| |c} |ytj||D cic]} | | |j| |c} |ycc} wcc} wcc} w)a Apply colors from a matplotlib colormap to a graph. Reads values from the `src_attr` and use a matplotlib colormap to produce a color. Write the color to `dest_attr`. Parameters ---------- G : nx.Graph The graph to read and compute colors for. src_attr : str or other attribute name The name of the attribute to read from the graph. dest_attr : str or other attribute name The name of the attribute to write to on the graph. map : matplotlib.colormap The matplotlib colormap to use. vmin : float, default None The minimum value for scaling the colormap. If `None`, find the minimum value of `src_attr`. vmax : float, default None The maximum value for scaling the colormap. If `None`, find the maximum value of `src_attr`. nodes : bool, default True Whether the attribute names are edge attributes or node attributes. rNTkeyscmapcFtdj|DS)Nc32K|]}t|ywN)float).0xs _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/networkx/drawing/nx_pylab.py z:apply_matplotlib_colors..do_map..fs9!U1X9s)tupleto_rgba)rmappers r do_mapz'apply_matplotlib_colors..do_mapds9v~~a'8999) matplotlibnodes is_multigraphedgesminmaxcmScalarMappableset_climnxset_node_attributesset_edge_attributes)Gsrc_attr dest_attrmapvminvmaxr(mpl type_iteravalsr%ner$s @r rr/s3D GGI  GGG& GGI  |t|09:1 ! X&:: <t9D <t9D VV " " " ,F OOD$:   CA6!''!*X.//CY   CA6!''!*X.//CY %;DDsD< E  E c 123456789:;ddlm}ddl5ddlm8ddl7iddddddd d d d d ddddddddddddddddddddd dd d dddddddddd dd! d"d#d$dd%|j rd&nd#d'|j rd(ndd)dddd*1D]}|1vstjd+|8jjd,1d,rjd-d-d.d.d.d./16fd0}15fd1}3fd2}12fd3}12fd43dZ126fd5 457fd6:7fd7;23459:;fd8} G78fd9d:5jj} jdd;} t| tr| r|j!} n=g} n:tj"|| dj%D cgc] \} }|s |  } } }|j'| 6jdd<9d=}t)9r%tj*696||9|d<nJtj"|9ik(r1tj*6tj,6||9|d<t/| dkDrKjdd>}|tj"6|1dj1D]}6j!|?D cgc]\} }||k(s | |1dk(r| }} }7j3||d<}7j3t5||d@||dADcgc]\}}|||c}}}7j3t7|D cgc]\}} 4| dBd.x}dk7r|n||c} }}j9|dddf|dddCf||dD||||dE|dFG jd dH}|g|d.urbi}t|t:r|}d}6j!|?D]6\} }|d.ur t|t:sdH||n| i}|jdH| }t|t<s t=|}|j?|6j | 9\}}j||||jdD1d dD|jd@1d d@|jdI1d dI|jdJ1d dJ|jdK1d dK|jdL1d dLj@|jdM1d dMN 9jdd;} t| tr| r|jC}!n=g}!n:tjD|| dj%D"cgc] \}"}|s |" }!}"}|jG|!2tItj"69tj*2tj"699O2jKr)2jCdPD"cgc] }"||"s |"c}"n&2jCD"cgc] }"||"s |"c}"}#2jKr)2jCdPD"cgc] }"||"r |"c}"n&2jCD"cgc] }"||"r |"c}"}$7j3|#D%&cgc]^}%}}&4|%d"`` if `G` is directed else ``"-"`` * - arrowsize - `"arrowsize"` - 10 if `G` is directed else 0 * - edge_curvature - `"curvature"` - arc3 * - edge_source_margin - `"source_margin"` - 0 * - edge_target_margin - `"target_margin"` - 0 Parameters ---------- G : graph A networkx graph canvas : Matplotlib Axes object, optional Draw the graph in specified Matplotlib axes pos : string or function, default "pos" A string naming the node attribute storing the position of nodes as a tuple. Or a function to be called with input `G` which returns the layout as a dict keyed by node to position tuple like the NetworkX layout functions. If no nodes in the graph has the attribute, a spring layout is calculated. node_visible : string or bool, default visible A string naming the node attribute which stores if a node should be drawn. If `True`, all nodes will be visible while if `False` no nodes will be visible. If incomplete, nodes missing this attribute will be shown by default. node_color : string, default "color" A string naming the node attribute which stores the color of each node. Visible nodes without this attribute will use '#1f78b4' as a default. node_size : string or number, default "size" A string naming the node attribute which stores the size of each node. Visible nodes without this attribute will use a default size of 300. node_label : string or bool, default "label" A string naming the node attribute which stores the label of each node. The attribute value can be a string, False (no label for that node), True (the node is the label) or a dict keyed by node to the label. If a dict is specified, these keys are read to further control the label: * label : The text of the label; default: name of the node * size : Font size of the label; default: 12 * color : Font color of the label; default: black * family : Font family of the label; default: "sans-serif" * weight : Font weight of the label; default: "normal" * alpha : Alpha value of the label; default: 1.0 * h_align : The horizontal alignment of the label. one of "left", "center", "right"; default: "center" * v_align : The vertical alignment of the label. one of "top", "center", "bottom"; default: "center" * bbox : A dict of parameters for `matplotlib.patches.FancyBboxPatch`. Visible nodes without this attribute will be treated as if the value was True. node_shape : string, default "shape" A string naming the node attribute which stores the label of each node. The values of this attribute are expected to be one of the matplotlib shapes, one of 'so^>v"`` for directed graphs. See `matplotlib.patches.ArrowStyle` for more options arrowsize : string or int, default "arrow_size" A string naming the edge attribute which stores the size of the arrowhead for each edge. Visible edges without this attribute will use a default value of 10. edge_curvature : string, default "curvature" A string naming the edge attribute storing the curvature and connection style of each edge. Visible edges without this attribute will use "arc3" as a default value, resulting an a straight line between the two nodes. Curvature can be given as 'arc3,rad=0.2' to specify both the style and radius of curvature. Please see `matplotlib.patches.ConnectionStyle` and `matplotlib.patches.FancyArrowPatch` for more information. edge_source_margin : string or int, default "source_margin" A string naming the edge attribute which stores the minimum margin (gap) between the source node and the start of the edge. Visible edges without this attribute will use a default value of 0. edge_target_margin : string or int, default "target_margin" A string naming the edge attribute which stores the minimumm margin (gap) between the target node and the end of the edge. Visible edges without this attribute will use a default value of 0. hide_ticks : bool, default True Weather to remove the ticks from the axes of the matplotlib object. Raises ------ NetworkXError If a node or edge is missing a required parameter such as `pos` or if `display` receives an argument not listed above. ValueError If a node or edge has an invalid color format, i.e. not a color string, rgb tuple or rgba tuple. Returns ------- The input graph. This is potentially useful for dispatching visualization functions. r)CounterNnode_pos node_visibleT node_color#1f78b4 node_size, node_label z#000000 sans-serifnormal?center)sizecolorfamilyweightalphah_alignv_alignbbox node_shapeo node_alphanode_border_widthnode_border_colorface edge_visible edge_width edge_color edge_labelroundrKrKrKboxstyleecfc?) rMrNrOrPrQrTrRrSposrotate edge_style- edge_alphaedge_arrowstyle-|>edge_arrowsize arc3)edge_curvatureedge_source_marginedge_target_margin hide_ticksz-Unrecongized visualization keyword argument: rsbothFaxiswhichbottomleft labelbottom labelleftcd}|}j||3|D].}j|vstjdd|Ktjik(r2t fdj Dr|Dcgc]}c}S|Dcgc]!}j|j|#c}Scc}wcc}w)FReturn a list of attribute values for `seq`, using a default if needednode_ Attribute 'z' missing for node c38K|]\}}d|vs |k(yw)nodeNrkvattrs r r!z:display..node_property_sequence..H$!QFaKDAIH  )getr(r0 NetworkXErrorget_node_attributesanyitems) seqr param_namedefaultr=_defaultskwargs node_subgraphs ` r node_property_sequencez'display..node_property_sequencesTF^ :&zz*d+ ? W}22155**[>QRSQT+UVV W  &&}d;rAH&,,.HH"%&QD& &CFGa ##A&**49GG'G  C%&CcVt|tr>jjj |}|dk7r|d|d|d|fS|St|t rt |dk(r|d|d|d|fSt|t rt |dk(r|Std|)NrWrzInvalid format for color: ) isinstancestrcolorscolorConverterr#r"len ValueError)rNrQrgbarr9s r compute_colorszdisplay..compute_colorss eS !::,,44U;D..Qa$q'599K eU #E a!HeAha%8 8 eU #E aL5eW=>>r&c|ddk(xr5|ddk(xr'|ddk(xr|ddk(xr |d|dk7S) N arrowstyleri curvaturero source_marginr target_marginrr)r> get_edge_attrs r collection_compatiblez&display..collection_compatiblesk !\ *c 1 a-7 a1Q6 a1Q6  !!  r&cd}|}j||3|D].}j|vstjdd|Ktjik(r2t fdj Dr|Dcgc]}c}S|Dcgc]!}j|j|#c}Scc}wcc}w)r}edge_rz' missing for edge c38K|]\}}d|vs |k(yw)edgeNrrs r r!z:display..edge_property_sequence..rr)rr*r0rget_edge_attributesrr) rrrrr>rr edge_subgraphrs ` r edge_property_sequencez'display..edge_property_sequencesTF^ :&zz*d+ ? W}22155**[>QRSQT+UVV W  &&}d;rAH&,,.HH"%&QD& &CFGa ##A&**49GG'Grc4d|}|}j||}|,|j|vrtjd|d||-tj|ik(r|j vr|Sj|j||S)z@Return the final edge attribute value, using default if not Nonerrz' missing from edge )rr*r0rrvalues)r>rrrrrrs r rzdisplay..get_edge_attrsTF^ :&zz*d+ ?t=+>+>q+AA""[6J1##NO O  &&}d;rA 'K""1%))$88r&c@|rn }d|}|}j||}|,||j|vrtjd|d||-tj||ik(r|j vr|S|j|j||S)z@Return the final node attribute value, using default if not Noner~rz' missing from node )rr(r0rrr) r=ruse_edge_subgraphsubgraphrrrrrrs r get_node_attrzdisplay..get_node_attr.s$5==TF^ :&zz*d+ ?t8>>!+<<""[6J1##NO O  &&x6"< 'K~~a $$T733r&cfd}|S)Nc 0j||k(stjd jj j |}j dz }|dz}jd|g||g|dgddg| dg| |gd|gg} dzrD|j\}} t dzD]} | | } } j|| gj} jj jj ||zgdS)ND`self_loop` connection style methodis only to be used for self-loopsHrerrrrrrrrr) allr0r transDatainverted transformsqrtasarrayTrangearraypathPath)posAposBargsrdata_locv_shifth_shiftrryrcanvas edge_indexr9rEnps r self_loop_connectionz8display..self_loop..self_loop_connectionDs766$$,'&&8 ''002<.self_loopCs% % N$#r&cb|dvrjd|zdz Sj|dz SNzs^>v.to_marker_edgems6 X 771t8$q( (774=1$ $r&c  |dd|dd}t||d} |dd|dd}t||d}jjj|dj|d|d|d|dk7r |dn(t |d k(rdn|d d z|dd|d |d |d |d||d S)NrrMshaperrrrrrrrNstylewidth arrowsize) rconnectionstylerN linestyle linewidthmutation_scaleshrinkAshrinkBzorder)r,patchesFancyArrowPatchr(r) r>rrrrrr9rfrrs r build_fancy_arrowz"display..build_fancy_arrowssV& !A$ ' !A$ (   !_ - ' !A$ ' !A$ (   !_ - {{**   ! %c *   ! %c *$Q 5Q41Q4<a-Q1A!A$(!!A$/  7+#Aw/#Aw/(K8!!%+  r&cFeZdZddddfd ZdZfdZfdZxZS) display..CurvedArrowTextreFN label_poslabels_horizontalaxcH||_||_||_|j}||_|j |\|_|_|_t|(|j |jg|d|ji||jj|yNrotation arrowrrgcar_update_text_pos_anglerranglesuper__init__ add_artist selfrrrrrr __class__plts r rz)display..CurvedArrowText.__init__DJ'DN%6D "zWWYDG)-)D)DU)K &DFDFDJ G TVVTVV Rd RTZZ R6 R GG  t $r&c |j}|jj}|j|j |jd}|j |jd}|j ||f\}}|j |||j|j|j|z|j|z}|S|j|j}|S)U This is part of FancyArrowPatch._get_path_in_displaycoord It omits the second part of the method where path is converted to polygon based on width The transform is taken from ax, not the object, as the object has not been added yet, and doesn't have transform rrpatchApatchBrr) _dpi_corrr _posA_posB_convert_xy_unitsrget_connectionstylerrrrtransform_path_path_originalrrdpi_cor trans_datarr_paths r _get_arrow_path_dispz5display..CurvedArrowText._get_arrow_path_dispsnnG**J+..u/?/?/BC..u/?/?/BC)33T4LA t3113 << <<!MMG3!MMG3 L#11%2F2FGLr&cT|j|}|j\\}}\}}\}}|j} d| z } | dz|zd| z| z|zz| dz|zz} | dz|zd| z| z|zz| dz|zz} |jrd} ngd| z||z zd| z||z zz}d| z||z zd| z||z zz}j ||dj zz dz} | dkDr| dz} | dkr| dz } |j jjj| | f\} } | | | fSNrrrihZi) r verticesrrarctan2pirrrr)rr path_dispx1y1cxcyx2y2tttrrrchange_xchange_yrs r rz7display..CurvedArrowText._update_text_pos_anglesl11%8I+4+=+= (HRhr2RAQBA QURZ"_,q!tby8AA QURZ"_,q!tby8A%%r6R"W-Ab0AAr6R"W-Ab0AAHh71ruu9EL2:SLE3;SLEWW&&//1;;QFCFQa; r&c|j|j\|_|_|_|j |j|jf|j |jt|!|yr rrrrr set_position set_rotationrrrrendererrs r rz%display..CurvedArrowText.draw])-)D)DTZZ)P &DFDFDJ   tvvtvv. /   djj ) GL "r&__name__ __module__ __qualname__rr rr __classcell__)rrrs@r CurvedArrowTextrs' #  %2 8 4 # #r&r+visiblerfz!display's position attribute namer)datarNrQ border_colorrrM border_widthr)scr linewidths edgecolorsrlabelrOrPrRrSrT)rMrNrOrPhorizontalalignmentverticalalignmentrrT)namer)rrrr)rr2rrQ antialiasedsr)r-r) rMrNrOrPrQr5r6rrrTrrg) rMrNrOrPrQrTr5r6rrrrr)T)1 collectionsr@r'matplotlib.pyplotpyplotnumpy is_directedr0rrr tick_paramstextTextrboolr(rrrcallabler1 spring_layoutrrrzip enumeratescatterdictrupdaterr*rrprintr)LineCollectionadd_collection add_patchr"KeyErrorrrrrrremove_node_attributes)collection_edgesnon_collection_edgesur edge_positionedge_collection fancy_arrowsr^edge_label_datarconnectionstyle_objrr path_datarrrrr9rrrrfrrs< `` @@@@@@@@@@@r rrrs \$#*D** i* S * "  * c* c!*" S#*$ V%*& '*( c)** i+*, "!(W  -*D cE*F cG*H AMMO5I*J  "QK*L!S*HZ  ""?wG  ~ zz, 67  H4?2 H,9&44*($T% % % NV##((--V#r::ni8L,% GGIMM00L$GMMO !QSTA  JJ}-M **Z 'CB}  3}-/G '5z  3 '2 -  2++M:www*Hh,x= JJ| $ &&q)#.DAq KKWWVXl%;F%CDgggx '=g'FGwwx,)?)IJwwx,)?)IJ$'GGx 5i@%#&'')Xl5KI5V"W **WWVXl%;F%CD   @::ni8L,% GGIMM00L$GMMO !QSTA  OOM2M "  45r--mSA  & & ("''T'2Oq6KA6NO&,,. KA2G2Ja K  & & ("''T'2Sq:OPQ:RS&,,. OA6KA6Na O JJ -   1qa$?a$?  M q //88 )*:GD-.>H,-=wG()97C9  o.L  1$% .A/2LO   \!_ - . L'2JL*d#!   & & ( $7  j 1 *E"9&E GQaAe|s{c4(n JJ| $www'Hh,x=  -$Qtqt|&+&?&?&A#''11-2E2Ead2KC2PQ/d; ",,557FFyQ  ))!,1 ,)?)GH'''8L+A'+JK778Xl-CH-MN778Xl-CH-MN'''8L+A'+JK(+!8L#9)#D)'*gg!8L#9)#D'$..,)?)GH%( WWVXl%;F%CDgggx '=g'FGwwx,)?)IJwwx,)?)IJgggx '=g'FGWWVXl%;F%CD$'GGx 5i@%#&'')Xl5KI5V"W''%,)?)FG"%''(H\4J84T"U **# gE P && !!!%=> H[ D V  P K T O ~ -)!, -sr= k<k<l4l ( l $ l/l6 ll l+l l$$l$= l) l)# l. 1l55m  m c Lddlm}||j}n|j}|j d|.|j r|j }n|jd}d|vrd|v|d<t|f||d||j|jy)aIDraw the graph G with Matplotlib. Draw the graph as a simple representation with no node labels or edge labels and using the full Matplotlib figure area and no axis labels by default. See draw_networkx() for more full-featured drawing that allows title, axis labels etc. Parameters ---------- G : graph A networkx graph pos : dictionary, optional A dictionary with nodes as keys and positions as values. If not specified a spring layout positioning will be computed. See :py:mod:`networkx.drawing.layout` for functions that compute node positions. ax : Matplotlib Axes object, optional Draw the graph in specified Matplotlib axes. kwds : optional keywords See networkx.draw_networkx() for a description of optional keywords. Examples -------- >>> G = nx.dodecahedral_graph() >>> nx.draw(G) >>> nx.draw(G, pos=nx.spring_layout(G)) # use spring layout See Also -------- draw_networkx draw_networkx_nodes draw_networkx_edges draw_networkx_labels draw_networkx_edge_labels Notes ----- This function has the same name as pylab.draw and pyplot.draw so beware when using `from networkx import *` since you might overwrite the pylab.draw function. With pyplot use >>> import matplotlib.pyplot as plt >>> G = nx.dodecahedral_graph() >>> nx.draw(G) # networkx draw() >>> plt.draw() # pyplot draw() Also see the NetworkX drawing examples at https://networkx.org/documentation/latest/auto_examples/index.html rNw)rrrr with_labelslabels)rfr) r;r<gcf get_figure set_facecoloraxesradd_axesr set_axis_offdraw_if_interactive)r3rfrkwdsrcfs r rr sr$ z WWY ]]_S z 77B\*BD &$.]!,,t,OO r&c rddlm}ddlm}|tj j }|tj j }|tj j } ||z| zhdz tfd|Dr2dj|D cgc] } | vs|  c} } td| |jD cic] \} } | |vs | | } } } |jD cic] \} } | |vs | | }} } |jD cic] \} } | | vs | | }} } |tjj|}t ||fi| t||fd|i||r t||fi||j!ycc} wcc} } wcc} } wcc} } w) aCDraw the graph G using Matplotlib. Draw the graph with Matplotlib with options for node positions, labeling, titles, and many other drawing features. See draw() for simple drawing without labels or axes. Parameters ---------- G : graph A networkx graph pos : dictionary, optional A dictionary with nodes as keys and positions as values. If not specified a spring layout positioning will be computed. See :py:mod:`networkx.drawing.layout` for functions that compute node positions. arrows : bool or None, optional (default=None) If `None`, directed graphs draw arrowheads with `~matplotlib.patches.FancyArrowPatch`, while undirected graphs draw edges via `~matplotlib.collections.LineCollection` for speed. If `True`, draw arrowheads with FancyArrowPatches (bendable and stylish). If `False`, draw edges using LineCollection (linear and fast). For directed graphs, if True draw arrowheads. Note: Arrows will be the same color as edges. arrowstyle : str (default='-\|>' for directed graphs) For directed graphs, choose the style of the arrowsheads. For undirected graphs default to '-' See `matplotlib.patches.ArrowStyle` for more options. arrowsize : int or list (default=10) For directed graphs, choose the size of the arrow head's length and width. A list of values can be passed in to assign a different size for arrow head's length and width. See `matplotlib.patches.FancyArrowPatch` for attribute `mutation_scale` for more info. with_labels : bool (default=True) Set to True to draw labels on the nodes. ax : Matplotlib Axes object, optional Draw the graph in the specified Matplotlib axes. nodelist : list (default=list(G)) Draw only specified nodes edgelist : list (default=list(G.edges())) Draw only specified edges node_size : scalar or array (default=300) Size of nodes. If an array is specified it must be the same length as nodelist. node_color : color or array of colors (default='#1f78b4') Node color. Can be a single color or a sequence of colors with the same length as nodelist. Color can be string or rgb (or rgba) tuple of floats from 0-1. If numeric values are specified they will be mapped to colors using the cmap and vmin,vmax parameters. See matplotlib.scatter for more details. node_shape : string (default='o') The shape of the node. Specification is as matplotlib.scatter marker, one of 'so^>v>> G = nx.dodecahedral_graph() >>> nx.draw(G) >>> nx.draw(G, pos=nx.spring_layout(G)) # use spring layout >>> import matplotlib.pyplot as plt >>> limits = plt.axis("off") # turn off axis Also see the NetworkX drawing examples at https://networkx.org/documentation/latest/auto_examples/index.html See Also -------- draw draw_networkx_nodes draw_networkx_edges draw_networkx_labels draw_networkx_edge_labels r) signatureN>r3rfarrowsrec3&K|]}|v ywrr)rr valid_kwdss r r!z draw_networkx..s -11J  -sz, zReceived invalid argument(s): rr)inspectrqr;r<r parametersrr r rjoinrrr0drawingrDrm)r3rfrrrernrqrvalid_node_kwdsvalid_edge_kwdsvalid_label_kwdsr invalid_argsr node_kwds edge_kwds label_kwdsrts @r rrYsn"#  34??DDFO 34??DDFO !56AAFFH"O36FFKJ - --yyT!IQj5H!!IJ 9,HII"&**,G$!Q!2FAGIG"&**,G$!Q!2FAGIG#'::<I41a18H3H!Q$IJI {jj&&q)3,),3;v;;Q2z2"JHGIs0* F"4F" F'-F' F-F-0 F3=F3cddlm}ddl}ddl}ddlm}ddl}| |j} | t|}t|dk(r|jjdS |j|Dcgc]}|| c}}t!||rt#|||||| }d}t!||j$sAt!|ts1|j't)t|Dcgc]}|c}}|j+|D]/}| j-|||k(df|||k(df|||||| || | |  }1|r| j/ddd d d d |-t!||r| j0|n| j1|j3d |Scc}w#t$r}tjd|d|d}~wwxYwcc}w) a Draw the nodes of the graph G. This draws only the nodes of the graph G. Parameters ---------- G : graph A networkx graph pos : dictionary A dictionary with nodes as keys and positions as values. Positions should be sequences of length 2. ax : Matplotlib Axes object, optional Draw the graph in the specified Matplotlib axes. nodelist : list (default list(G)) Draw only specified nodes node_size : scalar or array (default=300) Size of nodes. If an array it must be the same length as nodelist. node_color : color or array of colors (default='#1f78b4') Node color. Can be a single color or a sequence of colors with the same length as nodelist. Color can be string or rgb (or rgba) tuple of floats from 0-1. If numeric values are specified they will be mapped to colors using the cmap and vmin,vmax parameters. See matplotlib.scatter for more details. node_shape : string (default='o') The shape of the node. Specification is as matplotlib.scatter marker, one of 'so^>v>> G = nx.dodecahedral_graph() >>> nodes = nx.draw_networkx_nodes(G, pos=nx.spring_layout(G)) Also see the NetworkX drawing examples at https://networkx.org/documentation/latest/auto_examples/index.html See Also -------- draw draw_networkx draw_networkx_edges draw_networkx_labels draw_networkx_edge_labels r)IterableNzNode z has no position.r) r0r1rrr7r8rQr2r3r4rtFrur)collections.abcrr'matplotlib.collectionsr;r<r=rlistrr:PathCollectionrrNr0rr apply_alphandarrayrruniquerGr?margins set_zorder)r3rfnodelistrErCrUrQrr7r8rr2r3r4rrsrr9r'rrrxyerrrrnode_collections r rrsV)!# z WWY7 8}--d33H ZZ2AQ2 3%" UHdD$O  j"** -jT6RXX5X3GHazHI :& ** zU"A% & zU"A% &!!%       gx ( BJJ JJw q! W3 Hse+<=>CGHIs0"F1 F=F) GF G%F??GcNeZdZdZGddZ ddZdZdZy) FancyArrowFactoryz5Draw arrows with `matplotlib.patches.FancyarrowPatch`c eZdZddZdZdZy)(FancyArrowFactory.ConnectionStyleFactoryNcddl}ddl}ddl}||_||_||_|Dcgc]}|j j|c}|_t|j|_ ||_ ycc}wNr) r'matplotlib.pathr=rr9rrConnectionStylebase_connection_stylesrr=selfloop_height)rconnectionstylesrrr9r'rcss r rz1FancyArrowFactory.ConnectionStyleFactory.__init__sh $ " DGDHDG:J+46 ++B/+D '445DF#2D +s"A2c:|j||jzSr)rr=)rrs r curvedz/FancyArrowFactory.ConnectionStyleFactory.curveds..zDFF/BC Cr&cfd}|S)Nc  jj||k(stjd jj j j|}d jz}|dz} jjd|g||g|dgddg| dg| |gd|gg} dzrN|j\}} t dzD]} | | } }  jj|| gj} jjj jj j||zgdS)Nrg?rerrr)rrr0rrrrrrrrrrr9rr) rrrrrrrrrrrrrs r rzPFancyArrowFactory.ConnectionStyleFactory.self_loop..self_loop_connectionsLww{{44<0**<  77,,557AA$G 4 44!C-wwG  '* ! A!1 !7+G    >66DAq":>2% 1"1%77==!Q022Dxx}}))GG%%//4@BWr&r)rrrs`` r rz2FancyArrowFactory.ConnectionStyleFactory.self_loops# J( 'r&r)r'r(r)rrrrr&r ConnectionStyleFactoryrs 3 D& (r&rNcvddl}ddl}ddlm}ddl}t |t r|g}n4|j|r t|}nd}tj|||_ ||_ ||_ ||_||_||_||_||_||_||_||_|j-||||_| |_| |_|j4j6j9| | |_| |_||_t | tr#tA| tA|k7r tCdyy)NrzDConnectionStyleFactory arg `connectionstyle` must be str or iterablez1arrowsize should have the same length as edgelist)"r'matplotlib.patchesr;r<r=rriterablerr0rrr9redge_posedgelistrrUmin_source_marginmin_target_margin edge_indicesrErconnectionstyle_factoryrrrr to_rgba_array arrow_colorsrrrr)rrrrrrErrrUrrr]rQrrrrrr9r'rrmsgs r rzFancyArrowFactory.__init__s$( !!' os +./O [[ )"?3OXC""3' '      $!2!2("'+'B'B _b( $%"JJ55CCJPUV" i &3y>S]+JPQ Q,K &r&c  |j|\\}}\}}d}d}|jj|jrDt |jt s*t |jt s|j|}n |j}|jj|jrDt |jt s*t |jt s|j|} n |j} |jj|jr|j|dd\} } |j|jj| } |j|jj| } |j| |j}|j| |j}n(|j|j|j}|}t||}t|| }t |jt r|j|}n |j}t#|j$|kDr|j$|}nMt#|j$dk(r|j$d}n%|j$|t#|j$z}|jj|j&rNt#|j&|kDr|j&|}n2|j&|t#|j&z}n |j&}|jj|j(rt |j(t sht |j(t sNt#|j(|kDr|j(|}n2|j(|t#|j(z}n |j(}||k(r.||k(r)|j*j-|j.|}n(|j*j1|j.|}|jj|j2rDt |j2t s*t |j2t s|j2|}n |j2}|j4j6j9||f||f||||||||d S)Nrrr) rrrrrNrrrr)rrrrrrr"rrErrindexrrUr,rrrrrrrrrrrr9rr)rrUrrrr shrink_source shrink_targetrrsourcetargetsource_node_sizetarget_node_sizer arrow_colorrrrrs r __call__zFancyArrowFactory.__call__3s!]]1-R(2r  GG  T33 4t55s;t55u= $ 6 6q 9  $ 6 6  GG  T33 4t55s;t55u= $ 6 6q 9  $ 6 6  77  DNN +!]]1-bq1NFF#~~dmm.A.A&.IJ #~~dmm.A.A&.IJ  //0@$//RM //0@$//RM //PM)MM+<= M+<=  dnnd +!^^A.N!^^N t  !A %++A.K "" #q (++A.K++AD4E4E0F,FGK 77  DNN +4>>"Q& NN1-  NN1s4>>/B+BC I GG  TZZ (tzz3/tzz514::" JJqM  JJq3tzz?':;  I 8b"::DD!!!$O#::AA$BSBSTUBVWO GG  T__ -t4t6+JJxx// H H!!!)+0  r&c|dvr!|jjd|zdz S|jj|dz Sr)rr)r marker_sizers r rz FancyArrowFactory.to_marker_edges> X 77<<K014 477<< ,q0 0r&) rorVrirnrNrKsolidrrN)r'r(r)__doc__rrrrrr&r rrsF?8(8(D %4Rl_ B1r&rc( ddl}ddl}ddl}ddl}ddlm}ddl}| $|jxs|j }nt| ts td| }t|tr|g}n4|j|r t|}nd}tj ||rd}|'|j#|j%dt&d|d k7r'|j#|j%d t&d|dk7r'|j#|j%d t&d|dk7r'|j#|j%d t&dt)d |Dr'|j#|j%dt&d||jrdnd}| |j+} |t|j,}t/|r^|jr>t1j2d}|Dcgc]}t5|t7|dd}}ndgt/|z}ngS|t|j9}|d}|j;|Dcgc]}||d||dfc}} |j|rt/|t/| k(r|j=|D!cgc]}!t|!t>c}!r| "t| |j@jBsJ|jE} | tG|} | tI|} |j@jK| | }"|Dcgc]}| |"|}}|jM|jO| dddddf}#|jQ|jO| dddddf}$|jM|jO| dddddf}%|jQ|jO| dddddf}&|$|#z }'|&|%z }(|(dk7r|(n!d|jS|jIz})tU| |||||)||||||||||| }*|r|j0jW| ||d||}+|+jY| |+j[| | |+j]d|+j_|| ja|+|+},tjb|D-cgc] }-|-|vs|- }.}-|.rttet6|}/g}0|.D]=}-|/jg|-}1|*|1}2|0ji|2| jk|2?nEg},tmt/|D],}1|*|1}2| jk|2|,ji|2.d|'zd|(z}4}3|#|3z |%|4z f|$|3z|&|4zff}5| jo|5| jq|r| jsdddddd|,Scc}wcc}wcc}!wcc}wcc}-w)aDraw the edges of the graph G. This draws only the edges of the graph G. Parameters ---------- G : graph A networkx graph pos : dictionary A dictionary with nodes as keys and positions as values. Positions should be sequences of length 2. edgelist : collection of edge tuples (default=G.edges()) Draw only specified edges width : float or array of floats (default=1.0) Line width of edges edge_color : color or array of colors (default='k') Edge color. Can be a single color or a sequence of colors with the same length as edgelist. Color can be string or rgb (or rgba) tuple of floats from 0-1. If numeric values are specified they will be mapped to colors using the edge_cmap and edge_vmin,edge_vmax parameters. style : string or array of strings (default='solid') Edge line style e.g.: '-', '--', '-.', ':' or words like 'solid' or 'dashed'. Can be a single style or a sequence of styles with the same length as the edge list. If less styles than edges are given the styles will cycle. If more styles than edges are given the styles will be used sequentially and not be exhausted. Also, `(offset, onoffseq)` tuples can be used as style instead of a strings. (See `matplotlib.patches.FancyArrowPatch`: `linestyle`) alpha : float or array of floats (default=None) The edge transparency. This can be a single alpha value, in which case it will be applied to all specified edges. Otherwise, if it is an array, the elements of alpha will be applied to the colors in order (cycling through alpha multiple times if necessary). edge_cmap : Matplotlib colormap, optional Colormap for mapping intensities of edges edge_vmin,edge_vmax : floats, optional Minimum and maximum for edge colormap scaling ax : Matplotlib Axes object, optional Draw the graph in the specified Matplotlib axes. arrows : bool or None, optional (default=None) If `None`, directed graphs draw arrowheads with `~matplotlib.patches.FancyArrowPatch`, while undirected graphs draw edges via `~matplotlib.collections.LineCollection` for speed. If `True`, draw arrowheads with FancyArrowPatches (bendable and stylish). If `False`, draw edges using LineCollection (linear and fast). Note: Arrowheads will be the same color as edges. arrowstyle : str or list of strs (default='-\|>' for directed graphs) For directed graphs and `arrows==True` defaults to '-\|>', For undirected graphs default to '-'. See `matplotlib.patches.ArrowStyle` for more options. arrowsize : int or list of ints(default=10) For directed graphs, choose the size of the arrow head's length and width. See `matplotlib.patches.FancyArrowPatch` for attribute `mutation_scale` for more info. connectionstyle : string or iterable of strings (default="arc3") Pass the connectionstyle parameter to create curved arc of rounding radius rad. For example, connectionstyle='arc3,rad=0.2'. See `matplotlib.patches.ConnectionStyle` and `matplotlib.patches.FancyArrowPatch` for more info. If Iterable, index indicates i'th edge key of MultiGraph node_size : scalar or array (default=300) Size of nodes. Though the nodes are not drawn with this function, the node size is used in determining edge positioning. nodelist : list, optional (default=G.nodes()) This provides the node order for the `node_size` array (if it is an array). node_shape : string (default='o') The marker used for nodes, used in determining edge positioning. Specification is as a `matplotlib.markers` marker, e.g. one of 'so^>v>> G = nx.dodecahedral_graph() >>> edges = nx.draw_networkx_edges(G, pos=nx.spring_layout(G)) >>> G = nx.DiGraph() >>> G.add_edges_from([(1, 2), (1, 3), (2, 3)]) >>> arcs = nx.draw_networkx_edges(G, pos=nx.spring_layout(G)) >>> alphas = [0.3, 0.4, 0.5] >>> for i, arc in enumerate(arcs): # change alpha values of arcs ... arc.set_alpha(alphas[i]) The FancyArrowPatches corresponding to self-loops are not always returned, but can always be accessed via the ``patches`` attribute of the `matplotlib.Axes` object. >>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> G = nx.Graph([(0, 1), (0, 0)]) # Self-loop at node 0 >>> edge_collection = nx.draw_networkx_edges(G, pos=nx.circular_layout(G), ax=ax) >>> self_loop_fap = ax.patches[0] Also see the NetworkX drawing examples at https://networkx.org/documentation/latest/auto_examples/index.html See Also -------- draw draw_networkx draw_networkx_nodes draw_networkx_labels draw_networkx_edge_labels rNz.Argument `arrows` must be of type bool or NonezAdraw_networkx_edges arg `connectionstyle` must be str or iterablea The {0} keyword argument is not applicable when drawing edges with LineCollection. To make this warning go away, either specify `arrows=True` to force FancyArrowPatches or use the default values. Note that using FancyArrowPatches may be slow for large graphs. rr)category stacklevelrnrrrc3&K|] }|dk7 yw)roNr)rrs r r!z&draw_networkx_edges..s6rV|6srrlric,tjdSr itertoolscountrr&r z%draw_networkx_edges..s 8Jr&rr)r7r8{Gzt?rr8)rr2r9rrQg?rtFru):warningsr'rmatplotlib.colorsr;r<r=r>r)rrB TypeErrorrrrr0rwarnformat UserWarningrrr*rr: defaultdictnextr"r(rrrrColormapget_cmapr+r, NormalizeaminravelamaxrrrKset_cmapr/r set_labelrLselfloop_edgesr6rappendrMrupdate_datalimautoscale_viewr?)6r3rfrrr]rrQrr edge_cmap edge_vmin edge_vmaxrrrr4rErrUrrrrsrr9r'rruse_linecollectionr key_countr>rrr1 color_normalminxmaxxminymaxyrdhrfancy_arrow_factoryr^ edge_viz_objloopselfloops_to_drawedgelist_tuplearrow_collectionrUrpadxpadycornerss6 r r r sr!# ~"#--/"FQ__5FG&$'LM M!'Z/3'*+ _ %/Qs##  P   ! MM#**\2[UVM W ? MM#**[1KTUM V  ! MM ./+RS    ! MM ./+RS   6o6 6 MM ,- PQ   mmoU3  z WWY= 8} ?? #//0JKICKLaD52AaJq&)> ?  i)<)<= == I  JI  JIzz+++K :DEQi Q0E E 77288HQ1W-. /D 77288HQ1W-. /D 77288HQ1W-. /D 77288HQ1W-. /D t A t A 6aurxx /B/F/F/H'HO+    #*//88  9    +  I6""1%!!%( /*& /1.?.?.BWddhFVTWW !#eX"67N! ) $"((.+A. ''. U#  $  s8}% 'A'*E LL     & ' 4!8$Dd{D4K(4$;t *DDGg    kME?FjXs$!W;)X>X X , X6Xc`ddlm}| |j} |jDcic]}||c}t fd}fd}||d||d||d||d||d i}j D]}\}}||\}}t |ts t|}| j||||||d|||d|||d|||d|||d | | | j|| }|||<| r| jd d d d d d |Scc}w)a Draw node labels on the graph G. Parameters ---------- G : graph A networkx graph pos : dictionary A dictionary with nodes as keys and positions as values. Positions should be sequences of length 2. labels : dictionary (default={n: n for n in G}) Node labels in a dictionary of text labels keyed by node. Node-keys in labels should appear as keys in `pos`. If needed use: `{n:lab for n,lab in labels.items() if n in pos}` font_size : int or dictionary of nodes to ints (default=12) Font size for text labels. font_color : color or dictionary of nodes to colors (default='k' black) Font color string. Color can be string or rgb (or rgba) tuple of floats from 0-1. font_weight : string or dictionary of nodes to strings (default='normal') Font weight. font_family : string or dictionary of nodes to strings (default='sans-serif') Font family. alpha : float or None or dictionary of nodes to floats (default=None) The text transparency. bbox : Matplotlib bbox, (default is Matplotlib's ax.text default) Specify text box properties (e.g. shape, color etc.) for node labels. horizontalalignment : string or array of strings (default='center') Horizontal alignment {'center', 'right', 'left'}. If an array is specified it must be the same length as `nodelist`. verticalalignment : string (default='center') Vertical alignment {'center', 'top', 'bottom', 'baseline', 'center_baseline'}. If an array is specified it must be the same length as `nodelist`. ax : Matplotlib Axes object, optional Draw the graph in the specified Matplotlib axes. clip_on : bool (default=True) Turn on clipping of node labels at axis boundaries hide_ticks : bool, optional Hide ticks of axes. When `True` (the default), ticks and ticklabels are removed from the axes. To set ticks and tick labels to the pyplot default, use ``hide_ticks=False``. Returns ------- dict `dict` of labels keyed on the nodes Examples -------- >>> G = nx.dodecahedral_graph() >>> labels = nx.draw_networkx_labels(G, pos=nx.spring_layout(G)) Also see the NetworkX drawing examples at https://networkx.org/documentation/latest/auto_examples/index.html See Also -------- draw draw_networkx draw_networkx_nodes draw_networkx_edges draw_networkx_edge_labels rNct|tr7t|tk7rt|dj |yy)Nz% must have the same length as labels.)rrHrradd)p_valuep_nameindividual_paramsrfs r check_individual_paramsz5draw_networkx_labels..check_individual_paramsusC gt $7|s6{* F8+P!QRR  ! !& ) %r&c|vr||S|Srr)rrrrs r get_param_valuez-draw_networkx_labels..get_param_value{s & &4= r& font_size font_color font_weight font_familyrQ) rMrNrOrPrQr5r6rrTclip_onrtFru) r;r<rr(setrrrr@rr?)r3rfrfrrrrrQrTr5r6rrrsrr=rr text_itemsr4rrrrs ` @r r r shv$ z WWY ~ ! *1!Q$**  I{3J 5K7K7E7+JLLN5QA%%JE GG  I{;!!Z>"1k=A"1k=A!!UG4 3/ll   1 '*    k+s D+c/0123ddl1ddlm3ddl2G123fdd1jj }| dddd} t |tr|g}n22j|r t|}ntjd| 3j} |F|jrd d ini}|jd!d d i|Dcic]^}}t||}}}|siSt!|j#\/}|t|j%}2j'/Dcgc]}||d||d fc}}|jr>t)j*d }/Dcgc]}t-|t|dd}}ndgt//z}d}|rY2j12j3|ddddd f}2j52j3|ddddd f}||z }|dk7r|n!d2j7|j9z}t;|/|||||| } i0/0fd}!0fd}"|!|d|!|d|!|d|!|d|!| d|!| d|!| d|!|di}#t=t!/|D]p\}$\}}%t |%ts t|%}%|dd\}&}'| |$}(|&|'k(r|(j?})| j@jC||&}*|)|*|*}+| j@jEjG|+},|,jHd\}-}.| j |-|.|%|"|d|"|d|"|d|"|d|"|d|"| d|"| dd| j@| d ||#|< ||(|%|"|d|"|d|"|d|"|d|"|d|"| d|"| d| j@| d ||"|d|"| d | |#|<s|r| jKdddddd |#Scc}}wcc}wcc}w)"a Draw edge labels. Parameters ---------- G : graph A networkx graph pos : dictionary A dictionary with nodes as keys and positions as values. Positions should be sequences of length 2. edge_labels : dictionary (default=None) Edge labels in a dictionary of labels keyed by edge two-tuple. Only labels for the keys in the dictionary are drawn. label_pos : float (default=0.5) Position of edge label along edge (0=head, 0.5=center, 1=tail) font_size : int (default=10) Font size for text labels font_color : color (default='k' black) Font color string. Color can be string or rgb (or rgba) tuple of floats from 0-1. font_weight : string (default='normal') Font weight font_family : string (default='sans-serif') Font family alpha : float or None (default=None) The text transparency bbox : Matplotlib bbox, optional Specify text box properties (e.g. shape, color etc.) for edge labels. Default is {boxstyle='round', ec=(1.0, 1.0, 1.0), fc=(1.0, 1.0, 1.0)}. horizontalalignment : string (default='center') Horizontal alignment {'center', 'right', 'left'} verticalalignment : string (default='center') Vertical alignment {'center', 'top', 'bottom', 'baseline', 'center_baseline'} ax : Matplotlib Axes object, optional Draw the graph in the specified Matplotlib axes. rotate : bool (default=True) Rotate edge labels to lie parallel to edges clip_on : bool (default=True) Turn on clipping of edge labels at axis boundaries node_size : scalar or array (default=300) Size of nodes. If an array it must be the same length as nodelist. nodelist : list, optional (default=G.nodes()) This provides the node order for the `node_size` array (if it is an array). connectionstyle : string or iterable of strings (default="arc3") Pass the connectionstyle parameter to create curved arc of rounding radius rad. For example, connectionstyle='arc3,rad=0.2'. See `matplotlib.patches.ConnectionStyle` and `matplotlib.patches.FancyArrowPatch` for more info. If Iterable, index indicates i'th edge key of MultiGraph hide_ticks : bool, optional Hide ticks of axes. When `True` (the default), ticks and ticklabels are removed from the axes. To set ticks and tick labels to the pyplot default, use ``hide_ticks=False``. Returns ------- dict `dict` of labels keyed by edge Examples -------- >>> G = nx.dodecahedral_graph() >>> edge_labels = nx.draw_networkx_edge_labels(G, pos=nx.spring_layout(G)) Also see the NetworkX drawing examples at https://networkx.org/documentation/latest/auto_examples/index.html See Also -------- draw draw_networkx draw_networkx_nodes draw_networkx_edges draw_networkx_labels rNcHeZdZddddfd ZdZfdZfdZxZS) 2draw_networkx_edge_labels..CurvedArrowTextreFNrcH||_||_||_|j}||_|j |\|_|_|_t|(|j |jg|d|ji||jj|yrrrs r rz;draw_networkx_edge_labels..CurvedArrowText.__init__ rr&c |j}|jj}|j t d|j |jd}|j |jd}|j ||f\}}|j|||j|j|j|z|j|z}|S)rzPCan only draw labels for fancy arrows with posA and posB inputs, not custom pathrrr) rrrrrrrrrrrrrs r r zGdraw_networkx_edge_labels..CurvedArrowText._get_arrow_path_disp8 snnG**J' <**5+;+;A+>?D**5+;+;A+>?D%//t =LT4/E--/|||| / / ELr&cL|j}d|z }|j|}t|jjj j }|r.|j\}\}}\} } }||z| |zz} ||z| |zz} nS|j\\} }\}}\}}|dz| zd|z|z|zz|dz|zz} |dz|zd|z|z|zz|dz|zz} |jrd}n{|r z dz } z dz }n.d|z z zd|z|z zz}d|zz zd|z|z zz}j||djzz dz}|dkDr|dz}n |dkr|dz }|jjjj| | f\} } | | |fSr)rr rrrrBarrrrrrrrr)rrrrr is_bar_stylercx1cy1cx2cy2rrrrrrrrrrrr9rs r rzIdraw_networkx_edge_labels..CurvedArrowText._update_text_pos_angleU sAQB11%8I%))+S[[-H-H-L-LL/8/A/A,:CzS1"HsQw&"HsQw&09/A/A,R(2rHREBJQb01a4"9<EBJQb01a4"9<%% #c QH #c QH 2vb1AER"W4EEH 2vb1AER"W4EEH 8X6!bee)DsJ2:SLES[SLEWW&&//1;;QFCFQa; r&c|j|j\|_|_|_|j |j|jf|j |jt|!|yrr r#s r rz7draw_networkx_edge_labels..CurvedArrowText.draw r%r&r&)rr9rrs@r r+r s( #  %2 :( T # #r&r+r_r`razNdraw_networkx_edges arg `connectionstyle` must bestring or iterable of stringsrTr-rc,tjdSrrrr&r rz+draw_networkx_edge_labels.. sIOOA4Fr&rrrct|tr9t|tk7rt|d|j |<yy)Nz' must have the same length as edgelist.)rrrriter)rrrrs r rz:draw_networkx_edge_labels..check_individual_params sF gt $7|s8}, F8+R!STT(/  f % %r&c,|vrt|S|Sr)r)rrrs r rz2draw_networkx_edge_labels..get_param_value s" & &)&12 2r&rrrrQr5r6rgrr) rMrNrOrPrQr5r6rrrTrr)rMrNrOrPrQr5r6rrTrrrrrrtFrur)&r'r;r<r=r@rArrrrr0rrr)r*r"rErr(rr:rrrrrrrr,rrFrrrrrrr?)4r3rf edge_labelsrrrrrrQrTr5r6rrgrrErrrsr+rnrdrfr>rrrrrrrrrrrrUr4n1n2rrarrrbrrrrr9rrs4 @@@@@r r r sb#g#g##((--g#T |#?/R/3'*+ _ %/ ,   z WWY!"!2~6=agg6P46P46PQ(4uT{A~Q Q  K--/0Hf ?zz8DaC!Is1Q4y1DEH++,FG ?GH!YuQrU|45H HsS]* AwwrxxAq 123wwrxxAq 123 4K6aurxx /B/F/F/H'HO+  7 I{3J 5K7E7+/1FG-/BCFH-I{3J%c(F&;<7=D%%%JEbqB#A& 8"'";";"= <<))#b'2D+D$7I --/>>yII%%a(DAq!ww$Y <%j,?&{MB&{MB%eW5$3')>%#2%':#,,' ' Jt , /$Y <%j,?&{MB&{MB%eW5$3')>%#2%':#,,))[A&5fh&G"G) Jt E7r    EREIsP5&P;.!Qc Ft|fdtj|i|y)aEDraw the graph `G` with a bipartite layout. This is a convenience function equivalent to:: nx.draw(G, pos=nx.bipartite_layout(G), **kwargs) Parameters ---------- G : graph A networkx graph kwargs : optional keywords See `draw_networkx` for a description of optional keywords. Raises ------ NetworkXError : If `G` is not bipartite. Notes ----- The layout is computed each time this function is called. For repeated drawing it is much more efficient to call `~networkx.drawing.layout.bipartite_layout` directly and reuse the result:: >>> G = nx.complete_bipartite_graph(3, 3) >>> pos = nx.bipartite_layout(G) >>> nx.draw(G, pos=pos) # Draw the original graph >>> # Draw a subgraph, reusing the same node positions >>> nx.draw(G.subgraph([0, 1, 2]), pos=pos, node_color="red") Examples -------- >>> G = nx.complete_bipartite_graph(2, 5) >>> nx.draw_bipartite(G) See Also -------- :func:`~networkx.drawing.layout.bipartite_layout` rfN)rr0bipartite_layoutr3rs r r r  s"R 1##A&1&1r&c Ft|fdtj|i|y)aDraw the graph `G` with a circular layout. This is a convenience function equivalent to:: nx.draw(G, pos=nx.circular_layout(G), **kwargs) Parameters ---------- G : graph A networkx graph kwargs : optional keywords See `draw_networkx` for a description of optional keywords. Notes ----- The layout is computed each time this function is called. For repeated drawing it is much more efficient to call `~networkx.drawing.layout.circular_layout` directly and reuse the result:: >>> G = nx.complete_graph(5) >>> pos = nx.circular_layout(G) >>> nx.draw(G, pos=pos) # Draw the original graph >>> # Draw a subgraph, reusing the same node positions >>> nx.draw(G.subgraph([0, 1, 2]), pos=pos, node_color="red") Examples -------- >>> G = nx.path_graph(5) >>> nx.draw_circular(G) See Also -------- :func:`~networkx.drawing.layout.circular_layout` rfN)rr0circular_layoutrs r r r K s"H 0""1%00r&c Ft|fdtj|i|y)aDraw the graph `G` with a Kamada-Kawai force-directed layout. This is a convenience function equivalent to:: nx.draw(G, pos=nx.kamada_kawai_layout(G), **kwargs) Parameters ---------- G : graph A networkx graph kwargs : optional keywords See `draw_networkx` for a description of optional keywords. Notes ----- The layout is computed each time this function is called. For repeated drawing it is much more efficient to call `~networkx.drawing.layout.kamada_kawai_layout` directly and reuse the result:: >>> G = nx.complete_graph(5) >>> pos = nx.kamada_kawai_layout(G) >>> nx.draw(G, pos=pos) # Draw the original graph >>> # Draw a subgraph, reusing the same node positions >>> nx.draw(G.subgraph([0, 1, 2]), pos=pos, node_color="red") Examples -------- >>> G = nx.path_graph(5) >>> nx.draw_kamada_kawai(G) See Also -------- :func:`~networkx.drawing.layout.kamada_kawai_layout` rfN)rr0kamada_kawai_layoutrs r rrr s"J 4&&q)4V4r&c Ft|fdtj|i|y)aDraw the graph `G` with a random layout. This is a convenience function equivalent to:: nx.draw(G, pos=nx.random_layout(G), **kwargs) Parameters ---------- G : graph A networkx graph kwargs : optional keywords See `draw_networkx` for a description of optional keywords. Notes ----- The layout is computed each time this function is called. For repeated drawing it is much more efficient to call `~networkx.drawing.layout.random_layout` directly and reuse the result:: >>> G = nx.complete_graph(5) >>> pos = nx.random_layout(G) >>> nx.draw(G, pos=pos) # Draw the original graph >>> # Draw a subgraph, reusing the same node positions >>> nx.draw(G.subgraph([0, 1, 2]), pos=pos, node_color="red") Examples -------- >>> G = nx.lollipop_graph(4, 3) >>> nx.draw_random(G) See Also -------- :func:`~networkx.drawing.layout.random_layout` rfN)rr0 random_layoutrs r rr s"H .  #.v.r&c Ft|fdtj|i|y)aODraw the graph `G` with a spectral 2D layout. This is a convenience function equivalent to:: nx.draw(G, pos=nx.spectral_layout(G), **kwargs) For more information about how node positions are determined, see `~networkx.drawing.layout.spectral_layout`. Parameters ---------- G : graph A networkx graph kwargs : optional keywords See `draw_networkx` for a description of optional keywords. Notes ----- The layout is computed each time this function is called. For repeated drawing it is much more efficient to call `~networkx.drawing.layout.spectral_layout` directly and reuse the result:: >>> G = nx.complete_graph(5) >>> pos = nx.spectral_layout(G) >>> nx.draw(G, pos=pos) # Draw the original graph >>> # Draw a subgraph, reusing the same node positions >>> nx.draw(G.subgraph([0, 1, 2]), pos=pos, node_color="red") Examples -------- >>> G = nx.path_graph(5) >>> nx.draw_spectral(G) See Also -------- :func:`~networkx.drawing.layout.spectral_layout` rfN)rr0spectral_layoutrs r rr s"N 0""1%00r&c Ft|fdtj|i|y)aVDraw the graph `G` with a spring layout. This is a convenience function equivalent to:: nx.draw(G, pos=nx.spring_layout(G), **kwargs) Parameters ---------- G : graph A networkx graph kwargs : optional keywords See `draw_networkx` for a description of optional keywords. Notes ----- `~networkx.drawing.layout.spring_layout` is also the default layout for `draw`, so this function is equivalent to `draw`. The layout is computed each time this function is called. For repeated drawing it is much more efficient to call `~networkx.drawing.layout.spring_layout` directly and reuse the result:: >>> G = nx.complete_graph(5) >>> pos = nx.spring_layout(G) >>> nx.draw(G, pos=pos) # Draw the original graph >>> # Draw a subgraph, reusing the same node positions >>> nx.draw(G.subgraph([0, 1, 2]), pos=pos, node_color="red") Examples -------- >>> G = nx.path_graph(20) >>> nx.draw_spring(G) See Also -------- draw :func:`~networkx.drawing.layout.spring_layout` rfN)rr0rDrs r rr s"P .  #.v.r&c Jt|fdtj||i|y)aDraw networkx graph `G` with shell layout. This is a convenience function equivalent to:: nx.draw(G, pos=nx.shell_layout(G, nlist=nlist), **kwargs) Parameters ---------- G : graph A networkx graph nlist : list of list of nodes, optional A list containing lists of nodes representing the shells. Default is `None`, meaning all nodes are in a single shell. See `~networkx.drawing.layout.shell_layout` for details. kwargs : optional keywords See `draw_networkx` for a description of optional keywords. Notes ----- The layout is computed each time this function is called. For repeated drawing it is much more efficient to call `~networkx.drawing.layout.shell_layout` directly and reuse the result:: >>> G = nx.complete_graph(5) >>> pos = nx.shell_layout(G) >>> nx.draw(G, pos=pos) # Draw the original graph >>> # Draw a subgraph, reusing the same node positions >>> nx.draw(G.subgraph([0, 1, 2]), pos=pos, node_color="red") Examples -------- >>> G = nx.path_graph(4) >>> shells = [[0], [1, 2, 3]] >>> nx.draw_shell(G, nlist=shells) See Also -------- :func:`~networkx.drawing.layout.shell_layout` rf)nlistN)rr0 shell_layout)r3rrs r rr s"T :/:6:r&c Ft|fdtj|i|y)a$Draw a planar networkx graph `G` with planar layout. This is a convenience function equivalent to:: nx.draw(G, pos=nx.planar_layout(G), **kwargs) Parameters ---------- G : graph A planar networkx graph kwargs : optional keywords See `draw_networkx` for a description of optional keywords. Raises ------ NetworkXException When `G` is not planar Notes ----- The layout is computed each time this function is called. For repeated drawing it is much more efficient to call `~networkx.drawing.layout.planar_layout` directly and reuse the result:: >>> G = nx.path_graph(5) >>> pos = nx.planar_layout(G) >>> nx.draw(G, pos=pos) # Draw the original graph >>> # Draw a subgraph, reusing the same node positions >>> nx.draw(G.subgraph([0, 1, 2]), pos=pos, node_color="red") Examples -------- >>> G = nx.path_graph(4) >>> nx.draw_planar(G) See Also -------- :func:`~networkx.drawing.layout.planar_layout` rfN)rr0 planar_layoutrs r rrC s"R .  #.v.r&c Ft|fdtj|i|y)aDraw a networkx graph with forceatlas2 layout. This is a convenience function equivalent to:: nx.draw(G, pos=nx.forceatlas2_layout(G), **kwargs) Parameters ---------- G : graph A networkx graph kwargs : optional keywords See networkx.draw_networkx() for a description of optional keywords, with the exception of the pos parameter which is not used by this function. rfN)rr0forceatlas2_layoutrs r rro s!" 3%%a(3F3r&c ddlm}m}ddl}ddl} ddl} ddl} t|t|k(rSt|dtr@|jj|} | j||| j|} n6 | j|jj j|g} t|t| kDs| j$t|k(rA| j'| t|df} | d| dddf<| d| dddf<| d | ddd f<t)|||t| | ddd f<| S#t"$rK| j|D cgc]'} |jj j| )ncc} wc} } YwxYw#t*$r || ddd f<Y| SwxYw) aApply an alpha (or list of alphas) to the colors provided. Parameters ---------- colors : color string or array of floats (default='r') Color of element. Can be a single color format string, or a sequence of colors with the same length as nodelist. If numeric values are specified they will be mapped to colors using the cmap and vmin,vmax parameters. See matplotlib.scatter for more details. alpha : float or array of floats Alpha values for elements. This can be a single alpha value, in which case it will be applied to all the elements of color. Otherwise, if it is an array, the elements of alpha will be applied to the colors in order (cycling through alpha multiple times if necessary). elem_list : array of networkx objects The list of elements which are being colored. These could be nodes, edges or labels. cmap : matplotlib colormap Color map for use if colors is a list of floats corresponding to points on a color mapping. vmin, vmax : float Minimum and maximum values for normalizing colors if a colormap is used Returns ------- rgba_colors : numpy ndarray Array containing RGBA format values for each of the node colours. r)cycleisliceNrr)rrr)rr)rrrr)rr&r'r' matplotlib.cmrr=rrrr-r.r/r#rrrrrMresizerr)rrQ elem_listrr7r8r&r'r9r'rr$ rgba_colorsrNs r rr sJ( 6{c)n$F1Iv)F&&D&1d#nnV,  ((CJJ$=$=$E$Ef$M#NOK # u:K( (K,<,<I,N))K#i.!1DEK!,T!2KA !,T!2KA !,T!2KA  e c+6F!GH AqD % ((GMNe**2259NNK  #" ArE #s15E:BF+F(,,F  F('F(+GG)NNTr)NN)NrFrDrVNNNNNNNNNT)NrKrrNNrnNNNNNNrFNrVrorrT) NrHrrIrJNNrLrLNTT)NrernrrIrJNNrLrLNTTrFNroT)NNN)rr:rnumbersrnetworkxr0__all__rrrrrrr r r r r rrrrrrrrrr&r r0so& ,>B@ J U pL ^z@     !gTX1X1|      -rp     Vx      'sl )2X$1N%5P$/N'1T(/V*;Z)/X4(Jr&