
    \Mhڝ                    R   d Z ddlZddlZddlmZ ddlZg dZ	 d'dZ	 d(dZ	d)dZ
d'd	Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*dZ G d d          Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+dZ	 	 	 	 	 	 	 	 	 	 	 	 d,dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d-dZd Zd Zd Zd  Zd! Zd" Zd(d#Zd$ Zd% Zd.d&ZdS )/a  
**********
Matplotlib
**********

Draw networks with matplotlib.

Examples
--------
>>> G = nx.complete_graph(5)
>>> nx.draw(G)

See Also
--------
 - :doc:`matplotlib <matplotlib:index>`
 - :func:`matplotlib.pyplot.scatter`
 - :obj:`matplotlib.patches.FancyArrowPatch`
    N)Number)displayapply_matplotlib_colorsdrawdraw_networkxdraw_networkx_nodesdraw_networkx_edgesdraw_networkx_labelsdraw_networkx_edge_labelsdraw_bipartitedraw_circulardraw_kamada_kawaidraw_randomdraw_spectraldraw_springdraw_planar
draw_shelldraw_forceatlas2Tc                 V   	
 ddl }|r                                 n?                                 r                     d          n                                 ||1fdD             }|t	          |          }|t          |          }|j                            |          

                    ||           
fd	|r8t          j
          	fd                                 D             |           dS t          j          	fd	D             |           dS )
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.
    r   NTkeysc                 ,    g | ]}|                  S  r   ).0asrc_attr	type_iters     Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/networkx/drawing/nx_pylab.py
<listcomp>z+apply_matplotlib_colors.<locals>.<listcomp>[   s"    :::1	!X&:::    cmapc                 \    t          d                     |           D                       S )Nc              3   4   K   | ]}t          |          V  d S N)float)r   xs     r   	<genexpr>z:apply_matplotlib_colors.<locals>.do_map.<locals>.<genexpr>f   s(      99!U1XX999999r    )tupleto_rgba)r'   mappers    r   do_mapz'apply_matplotlib_colors.<locals>.do_mapd   s,    99v~~a'8'8999999r    c                 J    i | ]}| j         |                             S r   )nodes)r   nGr,   r   s     r   
<dictcomp>z+apply_matplotlib_colors.<locals>.<dictcomp>j   0    CCCA66!'!*X.//CCCr    c                 J    i | ]}| j         |                             S r   )edges)r   er0   r,   r   s     r   r1   z+apply_matplotlib_colors.<locals>.<dictcomp>n   r2   r    )
matplotlibr.   is_multigraphr4   minmaxcmScalarMappableset_climnxset_node_attributesset_edge_attributes)r0   r   	dest_attrmapvminvmaxr.   mplvalsr,   r+   r   s   ``       @@@r   r   r   /   s   D  GGII			
		 GGG&&		GGII	|t|:::::	:::<t99D<t99DV""",,F
OOD$: : : : :  

CCCCCCCCCY	
 	
 	
 	
 	
 	CCCCCCCCCY	
 	
 	
 	
 	
r    c                 .  &'()*+,-./012345 ddl m} ddl.ddlm1 ddl0i ddddddd	d
ddddddddddddddddddddddddddddddddddddd dd!
d"d#d$dd%|                                 rd&nd#d'|                                 rd(ndd)dddd**D ]}|*vrt          j        d+|           1	                                
                    d,*d,                   r                    d-d-d.d.d.d./           */fd0}*.fd1),fd2'*+fd3}*+fd4,db*+/fd5	-.0fd630fd75+,-.235fd8} G 01fd9d:.j        j                  }
                    dd;          }	t          |	t                    r|	r|                                 }
n5g }
n2d< t          j        | |	d                                          D             }
|                     |
          /
                    dd=          2d>}t)          2          r't          j        / 2/          |           |2|d<   nHt          j        | 2          i k    r/t          j        /t          j        /          |           |2|d<   t/          |
          dk    rJ
                    dd?          } |t          j        /|*d                                                             D ]4*4fd@/                    |A          D             }0                     ||d=                    }0                    )fdBt5           ||dC           ||dD                    D                       (0                    &(-fdEt7          |          D                       }                    |dddf         |dddFf          ||dG          (4 ||dH          |dIJ           
                    ddK          }||d.uri }t          |t:                    r|}d}/                    |A          D ]\  }}|d.u rt          |t:                    sdK||n|i}|
                    dK|          }t          |t<                    st=          |          }|                    |           /j        |         2         \  }}                    ||||
                    dG*d         dG                   |
                    dC*d         dC                   |
                    dL*d         dL                   |
                    dM*d         dM                   |
                    dN*d         dN                   |
                    dO*d         dO                   j         |
                    dP*d         dP                   Q           
                    dd;          }t          |t                    r|r| !                                }n5g }n2dR t          j"        | |d                                          D             }| #                    |          +tI          t          j        /2                     t          j        +t          j        /2          2S           +%                                r"'fdT+!                    dU          D             n'fdV+!                                D             }+%                                r"'fdW+!                    dU          D             n'fdX+!                                D             }0                    -fdY|D                       }t/          |          dk    r^.j         &                    | ||dC           ||dZ           ||d[           ||dD          d\dF]          }'                    |           i }t/          |          dk    r.|D ]+} ||          ||<   (                    ||                    ,
                    ddK          }i }t          |t:                    r|}dK}+%                                r+!                    |d^          n+!                    |A          } ||d.ur| D ]ѐ^ }}tS          |          }|d.u s|t          |t:                    sdK|i}|                    |           |
                    dK          }t          |t<                    st=          |          }	 ||         }!n# tT          $ r  ||          }!Y nw xY w|d         |dF         k    r|!+                                }"j         ,                    +j        |d                  2                   }# |"|#|#          }$j         -                                .                    |$          }%|%j/        d         \  }}                    ||||
                    dG*d         dG                   |
                    dC*d         dC                   |
                    dL*d         dL                   |
                    dM*d         dM                   |
                    dD*d         dD                   |
                    dN*d         dN                   |
                    dO*d         dO                   dj         |
                    dP*d         dP                   dF_           r ||!||
                    dG*d         dG                   |
                    dC*d         dC                   |
                    dL*d         dL                   |
                    dM*d         dM                   |
                    dD*d         dD                   |
                    dP*d         dP                   |
                    dN*d         dN                   |
                    dO*d         dO                   |
                    d=*d         d=                   |
                    d`*d         d`                   j         dFa           Ӊ2|k    rt          j0        | |           | S )ca6-  Draw the graph G.

    Draw the graph as a collection of nodes connected by edges.
    The exact details of what the graph looks like are controled by the below
    attributes. All nodes and nodes at the end of visible edges must have a
    position set, but nearly all other node and edge attributes are options and
    nodes or edges missing the attribute will use the default listed below. A more
    complete discription of each parameter is given below this summary.

    .. list-table:: Default Visualization Attributes
        :widths: 25 25 50
        :header-rows: 1

        * - Parameter
          - Default Attribute
          - Default Value
        * - pos
          - `"pos"`
          - If there is not position, a layout will be calculated with `nx.spring_layout`.
        * - node_visible
          - `"visible"`
          - True
        * - node_color
          - `"color"`
          - #1f78b4
        * - node_size
          - `"size"`
          - 300
        * - node_label
          - `"label"`
          - Dict describing the node label. Defaults create a black text with
            the node name as the label. The dict respects these keys and defaults:

            * size : 12
            * color : black
            * family : sans serif
            * weight : normal
            * alpha : 1.0
            * h_align : center
            * v_align : center
            * bbox : Dict describing a `matplotlib.patches.FancyBboxPatch`.
              Default is None.

        * - node_shape
          - `"shape"`
          - "o"
        * - node_alpha
          - `"alpha"`
          - 1.0
        * - node_border_width
          - `"border_width"`
          - 1.0
        * - node_border_color
          - `"border_color"`
          - Matching node_color
        * - edge_visible
          - `"visible"`
          - True
        * - edge_width
          - `"width"`
          - 1.0
        * - edge_color
          - `"color"`
          - Black (#000000)
        * - edge_label
          - `"label"`
          - Dict describing the edge label. Defaults create black text with a
            white bounding box. The dictionary respects these keys and defaults:

            * size : 12
            * color : black
            * family : sans serif
            * weight : normal
            * alpha : 1.0
            * bbox : Dict describing a `matplotlib.patches.FancyBboxPatch`.
              Default {"boxstyle": "round", "ec": (1.0, 1.0, 1.0), "fc": (1.0, 1.0, 1.0)}
            * h_align : "center"
            * v_align : "center"
            * pos : 0.5
            * rotate : True

        * - edge_style
          - `"style"`
          - "-"
        * - edge_alpha
          - `"alpha"`
          - 1.0
        * - arrowstyle
          - `"arrowstyle"`
          - ``"-|>"`` 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<dph8'. Visible nodes without this attribute will use 'o'.

    node_alpha : string, default "alpha"
        A string naming the node attribute which stores the alpha of each node.
        The values of this attribute are expected to be floats between 0.0 and 1.0.
        Visible nodes without this attribute will be treated as if the value was 1.0.

    node_border_width : string, default "border_width"
        A string naming the node attribute storing the width of the border of the node.
        The values of this attribute are expected to be numeric. Visible nodes without
        this attribute will use the assumed default of 1.0.

    node_border_color : string, default "border_color"
        A string naming the node attribute which storing the color of the border of the node.
        Visible nodes missing this attribute will use the final node_color value.

    edge_visible : string or bool, default "visible"
        A string nameing the edge attribute which stores if an edge should be drawn.
        If `True`, all edges will be drawn while if `False` no edges will be visible.
        If incomplete, edges missing this attribute will be shown by default. Values
        of this attribute are expected to be booleans.

    edge_width : string or int, default "width"
        A string nameing the edge attribute which stores the width of each edge.
        Visible edges without this attribute will use a default width of 1.0.

    edge_color : string or color, default "color"
        A string nameing the edge attribute which stores of color of each edge.
        Visible edges without this attribute will be drawn black. Each color can be
        a string or rgb (or rgba) tuple of floats from 0.0 to 1.0.

    edge_label : string, default "label"
        A string naming the edge attribute which stores the label of each edge.
        The values of this attribute can be a string, number or False or None. In
        the latter two cases, no edge label is displayed.

        If a dict is specified, these keys are read to further control the label:

        * label : The text of the label, or the name of an edge attribute holding the label.
        * 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`.
        * rotate : Whether to rotate labels to lie parallel to the edge, default: True.
        * pos : A float showing how far along the edge to put the label; default: 0.5.

    edge_style : string, default "style"
        A string naming the edge attribute which stores the style of each edge.
        Visible edges without this attribute will be drawn solid. Values of this
        attribute can be line styles, e.g. '-', '--', '-.' or ':' or words like 'solid'
        or 'dashed'. If no edge in the graph has this attribute and it is a non-default
        value, assume that it describes the edge style for all edges in the graph.

    edge_alpha : string or float, default "alpha"
        A string naming the edge attribute which stores the alpha value of each edge.
        Visible edges without this attribute will use an alpha value of 1.0.

    arrowstyle : string, default "arrow"
        A string naming the edge attribute which stores the type of arrowhead to use for
        each edge. Visible edges without this attribute use ``"-"`` for undirected graphs
        and ``"-|>"`` 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   )CounterNnode_posnode_visibleT
node_color#1f78b4	node_size,  
node_label   z#000000
sans-serifnormal      ?center)sizecolorfamilyweightalphah_alignv_alignbbox
node_shapeo
node_alphanode_border_widthnode_border_colorfaceedge_visible
edge_width
edge_color
edge_labelroundrR   rR   rR   boxstyleecfc      ?)
rT   rU   rV   rW   rX   r[   rY   rZ   posrotate
edge_style-
edge_alphaedge_arrowstyle-|>edge_arrowsize
   arc3)edge_curvatureedge_source_marginedge_target_margin
hide_ticksz-Unrecongized visualization keyword argument: rz   bothFaxiswhichbottomleftlabelbottom	labelleftc                 z   d }|                              |          .| D ]+}j        |         vrt          j        d d|           ,Tt          j                  i k    r;t          fd                                D                       rfd| D             S fd| D             S )FReturn a list of attribute values for `seq`, using a default if needednode_NAttribute 'z' missing for node c              3   2   K   | ]\  }}d |v 	|k    V  dS )nodeNr   r   kvattrs      r   r(   z:display.<locals>.node_property_sequence.<locals>.<genexpr>  /      HH$!QFaKKDAIKKKKHHr    c                     g | ]}S r   r   r   _r   s     r   r   z;display.<locals>.node_property_sequence.<locals>.<listcomp>      &&&QD&&&r    c                 R    g | ]#}j         |                                       $S r   )r.   get)r   r/   r   defaultnode_subgraphs     r   r   z;display.<locals>.node_property_sequence.<locals>.<listcomp>  1    GGGa#A&**499GGGr    )r   r.   r=   NetworkXErrorget_node_attributesanyitems)seqr   
param_namer/   r   defaultskwargsr   s    `  @r   node_property_sequencez'display.<locals>.node_property_sequence  s
    $T^^
:&zz*d++? W W}21555*+U+U+URS+U+UVVV 6 &}d;;rAAHHHH&,,..HHHHH B '&&&#&&&&GGGGGG3GGGGr    c                    t          | t                    rEj        j                            |           }|d         k    r|d         |d         |d         |fS |S t          | t
                    r+t          |           dk    r| d         | d         | d         |fS t          | t
                    rt          |           dk    r| S t          d|            )Nr^   r               zInvalid format for color: )
isinstancestrcolorscolorConverterr*   r)   len
ValueError)rU   rX   rgbar   rD   s      r   compute_colorszdisplay.<locals>.compute_colors  s    eS!! 	:,44U;;D...Qa$q'599KeU## 	9E

a!HeAha%88eU## 	E

aL=e==>>>r    c                      | d          dk    oA | d          dk    o1 | d          dk    o! | d          dk    o| d         | d         k    S )	N
arrowstylerp   	curvaturerv   source_marginr   target_marginr   r   )r5   get_edge_attrs    r   collection_compatiblez&display.<locals>.collection_compatible  s    M!\**c1 a--7a11Q6 a11Q6
 !!	
r    c                 z   d }|                              |          .| D ]+}j        |         vrt          j        d d|           ,Tt          j                  i k    r;t          fd                                D                       rfd| D             S fd| D             S )r   edge_Nr   z' missing for edge c              3   2   K   | ]\  }}d |v 	|k    V  dS )edgeNr   r   s      r   r(   z:display.<locals>.edge_property_sequence.<locals>.<genexpr>  r   r    c                     g | ]}S r   r   r   s     r   r   z;display.<locals>.edge_property_sequence.<locals>.<listcomp>  r   r    c                 R    g | ]#}j         |                                       $S r   )r4   r   )r   r5   r   r   edge_subgraphs     r   r   z;display.<locals>.edge_property_sequence.<locals>.<listcomp>  r   r    )r   r4   r=   r   get_edge_attributesr   r   )r   r   r   r5   r   r   r   r   s    `  @r   edge_property_sequencez'display.<locals>.edge_property_sequence  s
    $T^^
:&zz*d++? W W}21555*+U+U+URS+U+UVVV 6 &}d;;rAAHHHH&,,..HHHHH B '&&&#&&&&GGGGGG3GGGGr    c                 H   d| }|         }                     ||          }|)|j        |          vrt          j        d| d|            |1t          j        |          i k    r|                                v r|S j        |                               ||          S )z@Return the final edge attribute value, using default if not Noner   Nr   z' missing from edge )r   r4   r=   r   r   values)r5   r   r   r   r   r   r   s       r   r   zdisplay.<locals>.get_edge_attr  s     $T^^
:&zz*d++?t=+>q+AAA"#N#N#N1#N#NOOO &}d;;rAA''K"1%))$888r    c                 T   |rn	}d| }|         }                     ||          }|)||j        |          vrt          j        d| d|            |1t          j        ||          i k    r|                                v r|S |j        |                               ||          S )z@Return the final node attribute value, using default if not Noner   Nr   z' missing from node )r   r.   r=   r   r   r   )
r/   r   use_edge_subgraphsubgraphr   r   r   r   r   r   s
         r   get_node_attrzdisplay.<locals>.get_node_attr.  s    $5H===#T^^
:&zz*d++?t8>!+<<<"#N#N#N1#N#NOOO &x66"<<''K~a $$T7333r    c                       fd}|S )Nc           
      B                        | |k              st          j        d          j                                                            |           }                              dz  }|dz  }                    d|g||g|dgddg| dg| |gd|gg          }dz  r@|j        \  }}	t          dz            D ]}
|	| }	}
                    ||	g          j        }j                            j                            ||z             g d          S )ND`self_loop` connection style methodis only to be used for self-loopsH   rl   r   r   r   r   r   r   r   r   r   )allr=   r   	transDatainverted	transformsqrtasarrayTrangearraypathPath)posAposBargsr   data_locv_shifth_shiftr   r'   yr   canvas
edge_indexrD   rL   nps              r   self_loop_connectionz8display.<locals>.self_loop.<locals>.self_loop_connectionD  s]   66$$,'' &8   '0022<<TBBH ggi((2-GmG:: Lg&aLFXqMXw'L D  A~ *v1zA~.. ! !AqbqAAxxA'')8== **8d?;;=R=R=R  r    r   )r   rL   r   r   rD   r   s   `` r   	self_loopzdisplay.<locals>.self_loopC  s;    %	 %	 %	 %	 %	 %	 %	 %	 %	N $#r    c                 r    |dv r                     d| z            dz  S                      |           dz  S Nzs^>v<dr   )r   )rT   markerr   s     r   to_marker_edgezdisplay.<locals>.to_marker_edgem  s>    X771t8$$q((774==1$$r    c                     	 | d         d           | d         d                    }t          | | d                    } 	 | d         d           | d         d                    }t          | | d                    }j                            j        | d                           j        | d                            | d          | d         | d         k    r | d          n9 t	          |           d	k    rdn
| d	         d
z   | d         d                     | d           | d           | d           | d          ||d          S )Nr   rT   shaper   r   r   r   r   r   r   rU   stylewidth	arrowsize)	r   connectionstylerU   	linestyle	linewidthmutation_scaleshrinkAshrinkBzorder)r9   patchesFancyArrowPatchr.   r   )
r5   r   r   r   r   r   rD   rm   r   r   s
      r   build_fancy_arrowz"display.<locals>.build_fancy_arrows  s   &M!A$''M!A$((
 
 M!_--
 

 'M!A$''M!A$((
 
 M!_--
 
 {**!%c*!%c*$}Q55 Q41Q4<< a---YQ1AA!A$(!M!A$// 
  -7++#mAw//#mAw//(=K88!!% + 
 
 	
r    c                   F     e Zd Zdddd fd
Zd ZfdZ fdZ xZS )	 display.<locals>.CurvedArrowTextrl   FN	label_poslabels_horizontalaxc                N   || _         || _        || _        |                                }|| _        |                     |          \  | _        | _        | _         t                      j
        | j        | j        g|R d| j        i| | j                            |            d S Nrotationarrowr   r   gcar   _update_text_pos_angler'   r   anglesuper__init__
add_artist	selfr   r   r   r   r   r   	__class__plts	          r   r  z)display.<locals>.CurvedArrowText.__init__       DJ 'DN%6D"zWWYYDG)-)D)DU)K)K&DFDFDJ EGGTVTVRdRRRTZR6RRRGt$$$$$r    c           	         |j         }| j        j        }|j        |                    |j        d                   }|                    |j        d                   }|                    ||f          \  }} |                                |||j        |j        |j	        |z  |j
        |z            }n|                    |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
            Nr   r   patchApatchBr   r   )_dpi_corr   r   
_posA_posB_convert_xy_unitsr   get_connectionstyler  r  r   r   transform_path_path_originalr  r   dpi_cor
trans_datar   r   _paths          r   _get_arrow_path_dispz5display.<locals>.CurvedArrowText._get_arrow_path_disp  s     nG*J+..u/?/BCC..u/?/BCC)33T4LAAt31133 < <!MG3!MG3   #11%2FGGLr    c                 <   |                      |          }|j        \  \  }}\  }}\  }}| j        }	d|	z
  }
|
dz  |z  d|	z  |
z  |z  z   |	dz  |z  z   }|
dz  |z  d|	z  |
z  |z  z   |	dz  |z  z   }| j        rd}nhd|
z  ||z
  z  d|	z  ||z
  z  z   }d|
z  ||z
  z  d|	z  ||z
  z  z   }                    ||          dj        z  z  dz  }|dk    r|dz  }|dk     r|dz  }| j        j                                        	                    ||f          \  }}|||fS Nr   r   r   ih  Z      i)
r  verticesr   r   arctan2pir   r   r   r   )r  r   	path_dispx1y1cxcyx2y2tttr'   r   r   change_xchange_yr   s                   r   r   z7display.<locals>.CurvedArrowText._update_text_pos_angle  st   11%88I+4+=(HRhr2R AQBA
QURZ"_,q!tby8AA
QURZ"_,q!tby8A% ! r6R"W-Ab0AAr6R"W-Ab0AAHh771ru9EL2::SLE3;;SLEW&//11;;QFCCFQa;r    c                    |                      | j                  \  | _        | _        | _        |                     | j        | j        f           |                     | j                   t                                          |           d S r%   	r   r   r'   r   r   set_positionset_rotationr   r   r  rendererr  s     r   r   z%display.<locals>.CurvedArrowText.draw  t    )-)D)DTZ)P)P&DFDFDJtvtv.///dj)))GGLL"""""r    __name__
__module____qualname__r  r  r   r   __classcell__)r  r   r  s   @r   CurvedArrowTextr     s        
 #	% 	% 	% 	% 	% 	% 	% 	%2	 	 	8	 	 	 	 	4	# 	# 	# 	# 	# 	# 	# 	# 	#r    r6  visiblec                     g | ]	\  }}||
S r   r   )r   r/   r   s      r   r   zdisplay.<locals>.<listcomp>  2     
 
 
!QST

 
 
r    rm   z!display's position attribute namer   c                 B    g | ]\  }}|k    s|d         k    |S )Nr\   r   )r   r/   sr   r   s      r   r   zdisplay.<locals>.<listcomp>  sC          Aq::!),9O0O0O 0O0O0Or    )datac                 .    g | ]\  }} ||          S r   r   )r   cr   r   s      r   r   zdisplay.<locals>.<listcomp>'  s9       1 #N1a((  r    rU   rX   c                 P    g | ]"\  }} |d d          xdk    rn|         #S )border_colorFra   r   )r   ir/   r>  rU   r   s      r   r   zdisplay.<locals>.<listcomp>0  sj        1 "/ ! . %" " A "" "  #1X  r    r   rT   border_widthr   )r;  r>  r   
linewidths
edgecolorsr   labelrV   rW   rY   rZ   r[   )rT   rU   rV   rW   horizontalalignmentverticalalignmentr   r[   c                     g | ]	\  }}||
S r   r   )r   r5   r   s      r   r   zdisplay.<locals>.<listcomp>{  r9  r    )namec                 *    g | ]} |          |S r   r   r   r5   r   s     r   r   zdisplay.<locals>.<listcomp>  s*    OOOq6K6KA6N6NOOOOr    r   c                 *    g | ]} |          |S r   r   rK  s     r   r   zdisplay.<locals>.<listcomp>  s*    KKKA2G2G2J2JKaKKKr    c                 *    g | ]} |          |S r   r   rK  s     r   r   zdisplay.<locals>.<listcomp>  s+    SSSq:O:OPQ:R:RSSSSr    c                 *    g | ]} |          |S r   r   rK  s     r   r   zdisplay.<locals>.<listcomp>  s*    OOOA6K6KA6N6NOaOOOr    c                 N    g | ]!^}}} |d d           |d d          f"S )rm   T)r   r   )r   ur   r   r   s       r   r   zdisplay.<locals>.<listcomp>  s[     	
 	
 	

 1q a$???a$???	
 	
 	
r    r   r   r   )r   rC  r   rX   antialiasedsr   )r<  r   )rT   rU   rV   rW   rX   rF  rG  r   r   r[   r   rn   )rT   rU   rV   rW   rX   r[   rF  rG  r   r   r   r   r   )T)1collectionsrG   r6   matplotlib.pyplotpyplotnumpyis_directedr=   r   r   r   tick_paramstextTextr   boolr.   r   r   r   callabler>   spring_layoutr   r   r   zip	enumeratescatterdictr   updater   r4   r   r   printr7   LineCollectionadd_collection	add_patchr)   KeyErrorr  r   r   r  r  remove_node_attributes)6r0   r   r   rG   kwargr   r   r   r6  rI   visible_nodesdefault_display_pos_attrr\   nodes_with_shapepositionr@  rN   default_dictr/   lbllbl_textr'   r   rb   visible_edgescollection_edgesnon_collection_edgesedge_positionedge_collectionfancy_arrowsr5   re   edge_label_datar   connectionstyle_objr   r  	path_datar>  r   rU   r   r   r   r   r   rD   r   r   r  rm   r   r   r   s6    ``                                   @@@@@@@@@@@@@@@@r   r   r   r   sU   \ $###########*D** 	i* 	S	*
 	"	
 	
* 	c*  	c!*" 	S#*$ 	V%*& 	'*( 	c)** 	i+*, 	"!(WW
 
-*D 	cE*F 	cG*H 	AMMOO<55I*J 	6""QK*L !S* * *HZ     "GGG   !
 ~zz, 677 
 	 	
 	
 	
H H H H H H H4? ? ? ? ? ?2
 
 
 
 
H H H H H H H,9 9 9 9 9 9 9&4 4 4 4 4 4 4 4 4*($ ($ ($ ($ ($ ($ ($T% % % % %%
 %
 %
 %
 %
 %
 %
 %
 %
 %
 %
NV# V# V# V# V# V# V# V##(- V# V# V#r ::ni88L,%% 
 	GGIIMMMM
 
0L$GGMMOO
 
 
 JJ}--M **Z
'
'CB}} 6
33}--/G	
 	
 	
 '5z		3	'	'2	-	-
2+M::<T	
 	
 	
 '5z =AZZg66
W"z8L+A fhh
 
 3	 3	E         )//Z/@@      zz"8"89I5"Q"QRRHJJ    #../?II../?II! !   E ::      !**: ; ;   L" NNAA(()96BB112BNSS'  	 	 	 	 L'22J*E"9"9j$'' 	%LJ#))z):: 	 	FAse|| c4(( ?sA>www**Hh,, )x==JJ|$$$ &q)#.DAqKKWWVXl%;F%CDDgggx'=g'FGGwwx,)?)IJJwwx,)?)IJJ$'GGx5i@% % #&'')Xl5KI5V"W"W *WWVXl%;F%CDD     $ ::ni88L,%% 
 	GGIIMMMM
 
0L$GGMMOO
 
 
 OOM22M	"
 
4
4555r-mSAA    &&((	LOOOOM''T'22OOOOKKKK,,..KKK  &&((	PSSSSM''T'22SSSSOOOO,,..OOO 
 JJ	
 	
 	
 	

 -	
 	
 	
 M q  /88))*:GDD--.>HH,,-=wGG(()97CC 9 
 
 	o...L
  1$$% 	. 	.A//22LO\!_---- L'22JL*d## !

 &&((	2$777  j 11 
 *E"9"9& E	 E	GQaAe||s{c4(( %nJJ|$$$www''Hh,, )x==
-$Q - - -))!,,- tqt||&+&?&?&A&A#'11-2Ead2KC2PQQ//d;;	",5577FFyQQ	 )!,1,)?)GHH'''8L+A'+JKK778Xl-CH-MNN778Xl-CH-MNN'''8L+A'+JKK(+!8L#9)#D) ) '*gg!8L#9)#D' ' $.,)?)GHH%    ( OWWVXl%;F%CDDgggx'=g'FGGwwx,)?)IJJwwx,)?)IJJgggx'=g'FGGWWVXl%;F%CDD$'GGx5i@% % #&'')Xl5KI5V"W"W''%,)?)FGG"%''(H\4J84T"U"U *#    * &&&
!!%=>>>Hs   +d44eec                 ~   ddl m} ||                                }n|                                }|                    d           |1|j        r|                                }n|                    d          }d|vrd|v |d<   t          | f||d| |	                                 |
                                 dS )aI  Draw 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
    r   Nw)r   r   r   r   with_labelslabels)rm   r   )rT  rU  gcf
get_figureset_facecoloraxesr   add_axesr   set_axis_offdraw_if_interactive)r0   rm   r   kwdsr  cfs         r   r   r   
  s    r $#####	zWWYY]]__S	z7 	+BB\**BD  &$.]!,,,t,,,OO
Fr    c                 L   ddl m} ddlm}  |t                    j                                         |t                    j                                         |t                    j                                        z  z  h dz
  t          fd|D                       r3d
                    fd|D                       }t          d|           fd	|                                D             }fd
|                                D             }	fd|                                D             }
|t          j                            |           }t	          | |fi | t          | |fd|i|	 |rt          | |fi |
 |                                 dS )aC  Draw 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<dph8'.

    alpha : float or None (default=None)
        The node and edge transparency

    cmap : Matplotlib colormap, optional
        Colormap for mapping intensities of nodes

    vmin,vmax : float, optional
        Minimum and maximum for node colormap scaling

    linewidths : scalar or sequence (default=1.0)
        Line width of symbol border

    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.

    edge_cmap : Matplotlib colormap, optional
        Colormap for mapping intensities of edges

    edge_vmin,edge_vmax : floats, optional
        Minimum and maximum for edge colormap scaling

    style : string (default=solid line)
        Edge line style e.g.: '-', '--', '-.', ':'
        or words like 'solid' or 'dashed'.
        (See `matplotlib.patches.FancyArrowPatch`: `linestyle`)

    labels : dictionary (default=None)
        Node labels in a dictionary of text labels keyed by node

    font_size : int (default=12 for nodes, 10 for edges)
        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

    label : string, optional
        Label for graph legend

    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``.

    kwds : optional keywords
        See networkx.draw_networkx_nodes(), networkx.draw_networkx_edges(), and
        networkx.draw_networkx_labels() for a description of optional keywords.

    Notes
    -----
    For directed graphs, arrows  are drawn at the head end.  Arrows can be
    turned off with keyword arrows=False.

    Examples
    --------
    >>> 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>   r0   rm   arrowsr|  c              3       K   | ]}|vV  	d S r%   r   r   r   
valid_kwdss     r   r(   z draw_networkx.<locals>.<genexpr>  s(      
-
-11J
-
-
-
-
-
-r    z, c                     g | ]}|v|	S r   r   r  s     r   r   z!draw_networkx.<locals>.<listcomp>  s#    !I!I!IQj5H5H!5H5H5Hr    zReceived invalid argument(s): c                 $    i | ]\  }}|v 	||S r   r   )r   r   r   valid_node_kwdss      r   r1   z!draw_networkx.<locals>.<dictcomp>  )    GGG$!Q!2F2FA2F2F2Fr    c                 $    i | ]\  }}|v 	||S r   r   )r   r   r   valid_edge_kwdss      r   r1   z!draw_networkx.<locals>.<dictcomp>	  r  r    c                 $    i | ]\  }}|v 	||S r   r   )r   r   r   valid_label_kwdss      r   r1   z!draw_networkx.<locals>.<dictcomp>
  s*    III41a18H3H3H!Q3H3H3Hr    r  )inspectr  rT  rU  r   
parametersr   r	   r
   r   joinr   r   r=   drawingr]  r  )r0   rm   r  r|  r  r  r  invalid_args	node_kwds	edge_kwds
label_kwdsr  r  r  r  s              @@@@r   r   r   Y  s   n "!!!!!######
  i 344?DDFFOi 344?DDFFO y!566AFFHH "O36FF K K K J 
-
-
-
-
-
-
--- Jyy!I!I!I!IT!I!I!IJJH,HHIIIGGGG$**,,GGGIGGGG$**,,GGGIIIII4::<<IIIJ
{j&&q))3,,),,,3;;v;;;; 3Q22z222r    rM   rK   r]   c                    ddl m} ddl}ddl}ddlm} ddl}|
|                                }
|t          |           }t          |          dk    r|j
                            d          S 	 |                    fd|D                       }n+# t          $ r}t          j        d| d          |d}~ww xY wt!          ||          rt#          ||||||	          }d}t!          |j                  sPt!          t                    s;|                    fdt)          t          |                    D                       |                              D ];}|
                    ||k    df         ||k    df         ||||||	||||	          }<|r|
                    d
d
dddd           |0t!          ||          r |
j        |  n|
                    |           |                    d           |S )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<dph8'.

    alpha : float or array of floats (default=None)
        The node transparency.  This can be a single alpha value,
        in which case it will be applied to all the nodes 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).

    cmap : Matplotlib colormap (default=None)
        Colormap for mapping intensities of nodes

    vmin,vmax : floats or None (default=None)
        Minimum and maximum for node colormap scaling

    linewidths : [None | scalar | sequence] (default=1.0)
        Line width of symbol border

    edgecolors : [None | scalar | sequence] (default = node_color)
        Colors of node borders. 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.pyplot.scatter` for more details.

    label : [None | string]
        Label for legend

    margins : float or 2-tuple, optional
        Sets the padding for axis autoscaling. Increase margin to prevent
        clipping for nodes that are near the edges of an image. Values should
        be in the range ``[0, 1]``. See :meth:`matplotlib.axes.Axes.margins`
        for details. The default is `None`, which uses the Matplotlib default.

    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
    -------
    matplotlib.collections.PathCollection
        `PathCollection` of the nodes.

    Examples
    --------
    >>> 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   )IterableNc                      g | ]
}|         S r   r   )r   r   rm   s     r   r   z'draw_networkx_nodes.<locals>.<listcomp>  s    222AQ222r    zNode z has no position.c                     g | ]}S r   r   )r   r   r\   s     r   r   z'draw_networkx_nodes.<locals>.<listcomp>  s    HHHazHHHr    r   )
r;  r>  r   r"   rB   rC   rX   rC  rD  rE  r{   Fr|   r   )collections.abcr  r6   matplotlib.collectionsrT  rU  rV  r   listr   rS  PathCollectionr   rg  r=   r   r   apply_alphandarrayr   r   uniquer`  rX  margins
set_zorder)r0   rm   nodelistrL   rJ   r\   rX   r"   rB   rC   r   rC  rD  rE  r  rz   r  rD   r6   r  r   xyerrr   node_collections    `   `                   r   r   r     s   V )(((((!!!!######	zWWYY77
8}}--d333HZZ222222233 H H H=s===>>CGH %""  UHdD$OO
j"*-- JjT6R6R JXXHHHH5X3G3GHHHII
:&& 
 
**zU"A%&zU"A%&!! % 
 
  

 	 	
 	
 	
 gx(( 	 BJ   JJwq!!!s   0!B 
B:B55B:c                   V    e Zd ZdZ G d d          Z	 	 	 	 	 	 	 	 	 	 	 ddZd Zd Zd	S )FancyArrowFactoryz5Draw arrows with `matplotlib.patches.FancyarrowPatch`c                   "    e Zd ZddZd Zd ZdS )(FancyArrowFactory.ConnectionStyleFactoryNc                     dd l dd l}dd l}|| _        | _        || _        fd|D             | _        t          | j                  | _        || _	        d S )Nr   c                 D    g | ]}j                             |          S r   )r   ConnectionStyle)r   csrD   s     r   r   zEFancyArrowFactory.ConnectionStyleFactory.__init__.<locals>.<listcomp>  s6     + + +46++B//+ + +r    )
r6   matplotlib.pathrV  r   rD   r   base_connection_stylesr   r/   selfloop_height)r  connectionstylesr  r   r6   r   rD   s         @r   r  z1FancyArrowFactory.ConnectionStyleFactory.__init__  s    $$$$""""DGDHDG+ + + +:J+ + +D' 455DF#2D   r    c                 ,    | j         || j        z           S r%   )r  r/   )r  r   s     r   curvedz/FancyArrowFactory.ConnectionStyleFactory.curved  s    .zDF/BCCr    c                       fd}|S )Nc           
      b   j                             | |k              st          j        d          j        j                                                            |           }dj        z  }|dz  }j         	                    d|g||g|dgddg| dg| |gd|gg          }dz  rE|j
        \  }}	t          dz            D ]}
|	| }	}j                             ||	g          j
        }j        j                            j        j                            ||z             g d          S )Nr   g?rl   r   r   r   )r   r   r=   r   r   r   r   r   r  r   r   r   r   rD   r   r   )r   r   r   r   r   r   r   r   r'   r   r   r   r  s              r   r   zPFancyArrowFactory.ConnectionStyleFactory.self_loop.<locals>.self_loop_connection  s`   w{{44<00 *<    7,5577AA$GG 44!C-w G '* !A!1!7+G   > 36DAq":>22 % % 1"17==!Q002Dx}))G%//4@@BWBWBW  r    r   )r  r   r   s   `` r   r   z2FancyArrowFactory.ConnectionStyleFactory.self_loop  s+    # # # # # #J ('r    r%   )r2  r3  r4  r  r  r   r   r    r   ConnectionStyleFactoryr    sI        	3 	3 	3 	3	D 	D 	D&	( &	( &	( &	( &	(r    r  rv   r]   rp   ru   r   NrR   solidr   c                    dd l }dd l}dd lm} dd l}t          |t                    r|g}n;|                    |          rt          |          }nd}t          j
        |          || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        |                     |||          | _        |	| _        |
| _        |j        j                            ||          | _        || _        || _        t          |
t                    r/tA          |
          tA          |          k    rtC          d          d S d S )Nr   zDConnectionStyleFactory arg `connectionstyle` must be str or iterablez1arrowsize should have the same length as edgelist)"r6   matplotlib.patchesrT  rU  rV  r   r   iterabler  r=   r   r   rD   r   edge_posedgelistr  r\   min_source_marginmin_target_marginedge_indicesrL   r  connectionstyle_factoryr   r   r   r   to_rgba_arrayarrow_colorsr   r   r   r   )r  r  r  r  r  rL   r  r   r\   r   r   rd   rX   r   r   r  r  r   rD   r6   r  r   msgs                          r   r  zFancyArrowFactory.__init__  s   ( 	!   !!!!''''''os++ 	(./OO[[)) 	("?33OOXC"3'''   $!2!2("'+'B'B_b(
 (
$ %"J5CCJPUVV"
i&& 	R3y>>S]]+J+JPQQQ	R 	R+J+Jr    c                 	   | j         |         \  \  }}\  }}d}d}| j                            | j                  rBt	          | j        t
                    s(t	          | j        t                    s| j        |         }n| j        }| j                            | j                  rBt	          | j        t
                    s(t	          | j        t                    s| j        |         }	n| j        }	| j                            | j                  r| j	        |         d d         \  }
}| j        | j
                            |
                   }| j        | j
                            |                   }|                     || j                  }|                     || j                  }n"|                     | j        | j                  }|}t          ||          }t          ||	          }t	          | j        t                     r| j        |         }n| j        }t#          | j                  |k    r| j        |         }nHt#          | j                  dk    r| j        d         }n"| j        |t#          | j                  z           }| j                            | j                  rIt#          | j                  |k    r| j        |         }n*| j        |t#          | j                  z           }n| j        }| j                            | j                  r}t	          | j        t
                    sct	          | j        t                    sIt#          | j                  |k    r| j        |         }n*| j        |t#          | j                  z           }n| j        }||k    r,||k    r&| j                            | j        |                   }n%| j                            | j        |                   }| j                            | j                  rBt	          | j        t
                    s(t	          | j        t                    s| j        |         }n| j        }| j        j                            ||f||f||||||||d          S )Nr   r   r   )	r   r   r   r   rU   r   r   r   r   )r  r   r  r  r   r   r)   r  rL   r  r  indexr   r\   r9   r   r  r   r  r   r   r  r   r  r  r   rD   r   r   )r  rA  r   r!  r$  r%  shrink_sourceshrink_targetr  r  sourcetargetsource_node_sizetarget_node_sizer   arrow_colorr   r   r   r   s                       r   __call__zFancyArrowFactory.__call__3  sF   !]1-R(2rGT344	7t5s;;	7 t5u==	7
 !% 6q 9 $ 6 GT344	7t5s;;	7 t5u==	7
 !% 6q 9 $ 67DN++ 	*!]1-bqb1NFF#~dm.A.A&.I.IJ#~dm.A.A&.I.IJ //0@$/RRM //0@$/RRMM //PPM)MM+<==M+<== dnd++ 	,!^A.NN!^Nt !!A%%+A.KK"##q((+A.KK+AD4E0F0F,FGK7DN++ 	'4>""Q&& N1-		 N1s4>/B/B+BC		I GTZ((
	#tz3//
	# tz511
	#
 4:"" JqM		 Jq3tz??':;		
I88b":DD!!$ OO #:AA$BSTUBVWWO GT_--	)t44	) t66	)
 +JJJx//HH!!!)+ 0 
 
 	
r    c                     |dv r | j                             d|z            dz  S | j                             |          dz  S r   )r   r   )r  marker_sizer   s      r   r   z FancyArrowFactory.to_marker_edge  sC    X7<<K001447<<,,q00r    )rv   r]   rp   ru   r   NrR   r  r   r   N)r2  r3  r4  __doc__r  r  r  r   r   r    r   r  r    s        ??8( 8( 8( 8( 8( 8( 8( 8(D %4R 4R 4R 4Rl_
 _
 _
B1 1 1 1 1r    r  rR   r   r  ru   rv   c                 r  	23 ddl }ddl}ddl}ddl}ddlm} ddl}|*|                                 p|                                  }n't          |t                    st          d          | }t          |t                    r|g}n;|                    |          rt          |          }nd}t          j        |          |rd}|0|                    |                    d          t&          d           |d	k    r0|                    |                    d
          t&          d           |dk    r0|                    |                    d          t&          d           |dk    r0|                    |                    d          t&          d           t)          d |D                       r0|                    |                    d          t&          d           ||                                 rdnd}||                                }t          | j                  t/                    rL|                                 r$t1          j        d           33fdD             }ndgt/                    z  }ng S |!t          |                                           }|d}|                    fdD                       }|                    |          rt/          |          t/          |          k    r|                    d |D                       r	t          	|j        j                  sJ n|                                	|
tA          |          }
|tC          |          }|j        "                    |
|          22	fd|D             }|#                    |$                    |dddddf                             }|%                    |$                    |dddddf                             } |#                    |$                    |dddddf                             }!|%                    |$                    |dddddf                             }"| |z
  }#|"|!z
  }$|$dk    r|$n)d|&                    |          !                                z  }%tO          |||||%|||||||||||          }&|r"|j        (                    |||d||          }'|')                    	           |'*                    |
|           |'+                    d           |',                    |           |-                    |'           |'}(fdt          j.        |           D             })|)rst          t_          t`                              }*g }+|)D ]L},|*1                    |,          }- |&|-          }.|+2                    |.           |3                    |.           MnVg }(ti          t/                              D ]7}- |&|-          }.|3                    |.           |(2                    |.           8d|#z  d|$z  }0}/||/z
  |!|0z
  f| |/z   |"|0z   ff}1|5                    |1           |6                                 |r|7                    ddd d d d !           |(S )"a  Draw 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<dph8'.

    label : None or string
        Label for legend

    min_source_margin : int or list of ints (default=0)
        The minimum margin (gap) at the beginning of the edge at the source.

    min_target_margin : int or list of ints (default=0)
        The minimum margin (gap) at the end of the edge at the target.

    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
    -------
     matplotlib.collections.LineCollection or a list of matplotlib.patches.FancyArrowPatch
        If ``arrows=True``, a list of FancyArrowPatches is returned.
        If ``arrows=False``, a LineCollection is returned.
        If ``arrows=None`` (the default), then a LineCollection is returned if
        `G` is undirected, otherwise returns a list of FancyArrowPatches.

    Notes
    -----
    For directed graphs, arrows are drawn at the head end.  Arrows can be
    turned off with keyword arrows=False or by passing an arrowstyle without
    an arrow on the end.

    Be sure to include `node_size` as a keyword argument; arrows are
    drawn considering the size of nodes.

    Self-loops are always drawn with `~matplotlib.patches.FancyArrowPatch`
    regardless of the value of `arrows` or whether `G` is directed.
    When ``arrows=False`` or ``arrows=None`` and `G` is undirected, the
    FancyArrowPatches corresponding to the self-loops are not explicitly
    returned. They should instead be accessed via the ``Axes.patches``
    attribute (see examples).

    Examples
    --------
    >>> 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

    r   Nz.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.
r   r   )category
stacklevelru   r   r  r  c              3   "   K   | ]
}|d k    V  dS )rv   Nr   )r   r  s     r   r(   z&draw_networkx_edges.<locals>.<genexpr>  s&      66rV|666666r    r   rs   rp   c                  *    t          j        d          S Nr   	itertoolscountr   r    r   <lambda>z%draw_networkx_edges.<locals>.<lambda>  s    	8J8J r    c           
      d    g | ],}t          t          |d d                                      -S Nr   nextr)   r   r5   	key_counts     r   r   z'draw_networkx_edges.<locals>.<listcomp>  s4    LLLaD52A2<<!899LLLr    r   c                 H    g | ]}|d                   |d                  fS r   r   r   r   r5   rm   s     r   r   z'draw_networkx_edges.<locals>.<listcomp>  .    DDDaC!Is1Q4y1DDDr    c                 8    g | ]}t          |t                    S r   )r   r   )r   r>  s     r   r   z'draw_networkx_edges.<locals>.<listcomp>  s"    >>>aJq&))>>>r    )rB   rC   c                 8    g | ]}  |                    S r   r   )r   r5   color_normal	edge_cmaps     r   r   z'draw_networkx_edges.<locals>.<listcomp>  s+    EEEQiiQ00EEEr    r   {Gzt?r   rQ  )r   rC  rR  r   rX   c                     g | ]}|v |	S r   r   )r   loopr  s     r   r   z'draw_networkx_edges.<locals>.<listcomp>  s#    WWWddhFVFVTFVFVFVr    g?r{   Fr|   )8warningsr6   r  matplotlib.colorsrT  rU  rV  rW  r7   r   r[  	TypeErrorr   r  r  r=   r   warnformatUserWarningr   r   r4   r   rS  defaultdictr.   r   r   r   Colormapget_cmapr8   r9   	Normalizeaminravelamaxr   r  rd  set_cmapr<   r  	set_labelre  selfloop_edgesrA   r)   r  appendrf  r   update_datalimautoscale_viewrX  )4r0   rm   r  r   rd   r   rX   r   r   r  	edge_vmin	edge_vmaxr   r  rE  rL   r  r\   r   r  r  rz   r  rD   r6   r  r   use_linecollectionr  r  r  minxmaxxminymaxyr{  hr  fancy_arrow_factoryru  edge_viz_objselfloops_to_drawedgelist_tuplearrow_collectionr  rA  r   padxpadycornersr  r  s4    ``      `                                        @@r   r	   r	     s   r OOO!!!!###### ~"#--//"FQ__5F5FG&$'' 	NLMMM!'Z/3'' $*+	_	%	% $//Qs###
  P 	 !MM#**\22[UVMWWW??MM#**[11KTUMVVV!!MM

.//+RS     !!MM

.//+RS     66o66666 	MM

,--PQ    
 mmoo6UU3
	zWWYY==
8}} ?? 	/#/0J0JKKILLLL8LLLLL3X.LL			?? 
 zzDDDD8DDDEEH
 	JF__H--FF>>:>>>?? .  i)<======IJIJIz+++KKEEEEE*EEE
 77288HQQQ1W-..//D77288HQQQ1W-..//D77288HQQQ1W-..//D77288HQQQ1W-..//DtAtA
 66aaurxx	/B/B/F/F/H/H'HO+#  *   '/88 9 
 
 	  +++  I666""1%%%!!%(((
/***& XWWWb.?.B.BWWW 	$!#eX"6"677N!) $ $"((..++A.. ''...U####s8}}%% 	' 	'A''**ELL&&&& 4!8$Dd{D4K(4$;t*DDGg 

 	 	
 	
 	
 r    rO   rP   rQ   rS   c                    ddl m} ||                                }d |                                 D             t	                      fd}fd} ||d            ||d            ||d            ||d	            ||d
           i }                                D ]\  }}||         \  }}t          |t                    st          |          }|                    ||| |||d           |||d           |||d	           |||d           |||d
          |	|
|j	        ||          }|||<   |r|
                    dddddd           |S )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
    r   Nc                     i | ]}||S r   r   )r   r/   s     r   r1   z(draw_networkx_labels.<locals>.<dictcomp>q  s    ***1!Q***r    c                     t          | t                    rIt          |           t                    k    rt          | d                              |           d S d S )Nz% must have the same length as labels.)r   ra  r   r   add)p_valuep_nameindividual_paramsr}  s     r   check_individual_paramsz5draw_networkx_labels.<locals>.check_individual_paramsu  sg    gt$$ 	*7||s6{{** F!Q!Q!QRRR!!&)))))	* 	*r    c                      |v r||          S |S r%   r   )r   r  r  r  s      r   get_param_valuez-draw_networkx_labels.<locals>.get_param_value{  s    &&&4= r    	font_size
font_colorfont_weightfont_familyrX   )
rT   rU   rV   rW   rX   rF  rG  r   r[   clip_onr{   Fr|   )rT  rU  r   r.   setr   r   r   rY  r   rX  )r0   rm   r}  r"  r#  r%  r$  rX   r[   rF  rG  r   r&  rz   r  r  r!  
text_itemsr/   rE  r'   r   r&  r  s     `                    @r   r
   r
     s   v $#####	zWWYY~**		**** * * * * *    
 I{333J555K777K777E7+++JLLNN  5QA%%% 	JJEGG I{;;!/!Z>>"?1k=AA"?1k=AA!/!UG44 3/l  
 
 
1 

 	 	
 	
 	
 r    rl   c                 T	  ,-./01 ddl /ddlm1 ddl0 G /01fdd/j        j                  }|	dddd}	t          |t                    r|g}n90                    |          rt          |          }nt          j        d          |1                                }|3|                                 rd	d
ini }d  | j        d$dd
i|D             }|si S t          |                                 \  ,}|!t          |                                           }0                    fd,D                       }|                                 r$t'          j        d           ..fd,D             }ndgt+          ,          z  }d}|ro0                    0                    |dddddf                             }0                    0                    |dddddf                             }||z
  }|dk    r|n)d0                    |                                          z  }t7          |,||||||          }i -,-fd}-fd} ||d            ||d            ||d            ||d            ||
d            ||d            ||d            ||d           i }t9          t          ,|                    D ]\  } \  }!}"t          |"t                    st          |"          }"|!dd         \  }#}$ ||           }%|#|$k    r|%                                }&|j                            |#                   }' |&|'|'          }(|j                                         !                    |(          })|)j"        d         \  }*}+|                    |*|+|" ||d           ||d           ||d           ||d           ||d           ||
d           ||d          d|j        |	d|          ||!<   ; ||%|" ||d           ||d           ||d           ||d           ||d           ||
d           ||d          |j        |	d| ||d           ||d           |           ||!<   |r|#                    d!d!d"d"d"d"#           |S )%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
    r   Nc                   H     e Zd Zdddd fd
Zd ZfdZ fdZ xZS )	2draw_networkx_edge_labels.<locals>.CurvedArrowTextrl   FNr   c                N   || _         || _        || _        |                                }|| _        |                     |          \  | _        | _        | _         t                      j
        | j        | j        g|R d| j        i| | j                            |            d S r   r   r  s	          r   r  z;draw_networkx_edge_labels.<locals>.CurvedArrowText.__init__	  r  r    c           	         |j         }| j        j        }|j        t	          d          |                    |j        d                   }|                    |j        d                   }|                    ||f          \  }} |                                |||j        |j	        |j
        |z  |j        |z            }|S )r	  NzPCan only draw labels for fancy arrows with posA and posB inputs, not custom pathr   r   r
  )r  r   r   r  r   r  r   r  r  r  r   r   r  s          r   r  zGdraw_networkx_edge_labels.<locals>.CurvedArrowText._get_arrow_path_disp8	  s     nG*J' <   **5+;A+>??D**5+;A+>??D%//t==LT4/E--//||//  E Lr    c                    | j         }d|z
  }|                     |          }t          |                                j        j        j                  }|r)|j        \  }\  }}\  }	}
}||z  |	|z  z   }||z  |
|z  z   }nN|j        \  \  }}\  }}\  }}|dz  |z  d|z  |z  |z  z   |dz  |z  z   }|dz  |z  d|z  |z  |z  z   |dz  |z  z   }| j        rd}n||r|	|z
  dz  }|
|z
  dz  }n.d|z  ||z
  z  d|z  ||z
  z  z   }d|z  ||z
  z  d|z  ||z
  z  z   }	                    ||          dj
        z  z  dz  }|dk    r|dz  }n|dk     r|dz  }| j        j                                                            ||f          \  }}|||fS r  )r   r  r   r  r   r  Barr  r   r  r  r   r   r   r   )r  r   r&  r'  r  is_bar_styler   cx1cy1cx2cy2r'   r   r   r!  r"  r#  r$  r%  r   r(  r)  rD   r   s                         r   r   zIdraw_networkx_edge_labels.<locals>.CurvedArrowText._update_text_pos_angleU	  s    AQB11%88I%))++S[-H-L L  	=/8/A,:CzS1"HsQw&"HsQw& 09/A,R(2rHREBJQb01a4"9<EBJQb01a4"9<% !   F #c	QH #c	QHH 2vb1AER"W4EEH 2vb1AER"W4EEH

8X66!be)DsJ2::SLEES[[SLEW&//11;;QFCCFQa;r    c                    |                      | j                  \  | _        | _        | _        |                     | j        | j        f           |                     | j                   t                                          |           d S r%   r+  r.  s     r   r   z7draw_networkx_edge_labels.<locals>.CurvedArrowText.draw	  r0  r    r1  )r  rD   r   r  s   @r   r6  r+  	  s        
 #	% 	% 	% 	% 	% 	% 	% 	%2	 	 	:(	 (	 (	 (	 (	 (	T	# 	# 	# 	# 	# 	# 	# 	# 	#r    r6  rf   rg   rh   zNdraw_networkx_edges arg `connectionstyle` must bestring or iterable of stringsr   Tc                 4    i | ]^ }}t          |          |S r   )r)   )r   r   ds      r   r1   z-draw_networkx_edge_labels.<locals>.<dictcomp>	  s$    QQQ(4uT{{AQQQr    r<  c                 H    g | ]}|d                   |d                  fS r  r   r  s     r   r   z-draw_networkx_edge_labels.<locals>.<listcomp>	  r  r    c                  *    t          j        d          S r  r  r   r    r   r  z+draw_networkx_edge_labels.<locals>.<lambda>	  s    IOA4F4F r    c           
      d    g | ],}t          t          |d d                                      -S r  r  r  s     r   r   z-draw_networkx_edge_labels.<locals>.<listcomp>	  s4    HHH!YuQrrU||455HHHr    r   r  r  c                     t          | t                    rKt          |           t                    k    rt          | d          |                                 |<   d S d S )Nz' must have the same length as edgelist.)r   r  r   r   iter)r  r  r  r  s     r   r  z:draw_networkx_edge_labels.<locals>.check_individual_params	  sf    gt$$ 	77||s8}},, F!S!S!STTT(/f%%%	7 	7r    c                 :    |v rt          |                   S | S r%   )r  )r  r  r  s     r   r!  z2draw_networkx_edge_labels.<locals>.get_param_value	  s(    &&&)&1222r    r"  r#  r$  rX   rF  rG  rn   r   r   r%  )rT   rU   rV   rW   rX   rF  rG  r   r   r[   r   r&  )rT   rU   rV   rW   rX   rF  rG  r   r[   r   r&  r   r   r   r{   Fr|   r   )$r6   rT  rU  rV  rY  rZ  r   r   r  r  r=   r   r   r7   r4   r^  r   r.   r   rS  r  r   r  r   r  r   r9   r  r_  r  r   r   r   r  r  rX  )2r0   rm   edge_labelsr   r"  r#  r%  r$  rX   r[   rF  rG  r   rn   r&  rL   r  r   rz   r6  r  r}  r  r  r  r  r  r  r  r  r!  r(  rA  r   rE  n1n2r   rx  r   r  ry  r'   r   r  r  r  rD   r   r  s2    `                                          @@@@@@r   r   r     sh   b ######g# g# g# g# g# g# g# g# g##(- g# g# g#T |#?/RR/3'' 
*+	_	%	% 
//,
 
 	

 
zWWYY!"!2!2:~~QQgag6P6P46P46P6PQQQ 	K--//0Hf		?? zzDDDD8DDDEEH ++,F,FGG	HHHHxHHHsS]]*
 	
A wwrxxAAAq 12233wwrxxAAAq 122334K66aaurxx	/B/B/F/F/H/H'HO+	 	 	 7 7 7 7 7 7    
 I{333J555K777E7+++/1FGGG-/BCCCFH---I{333J%c(F&;&;<< 7 7=D%%%% 	JJEbqbB##A&&88"'";";"="=<))#b'22D++D$77I--//>>yIII%a(DAq!ww$_Y<<%oj,??&{MBB&{MBB%oeW55$3O')>% % #2/%':# # ,'  '    Jt,  /$_Y<<%oj,??&{MBB&{MBB%oeW55$3O')>% % #2/%':# # ,)/)[AA&5ofh&G&G"G)     Jt.  

 	 	
 	
 	
 r    c                 H    t          | fdt          j        |           i| dS )aE  Draw 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`
    rm   N)r   r=   bipartite_layoutr0   r   s     r   r   r   
  s1    R 	11#A&&1&11111r    c                 H    t          | fdt          j        |           i| dS )a  Draw 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`
    rm   N)r   r=   circular_layoutrC  s     r   r   r   K
  s1    H 	00"1%%000000r    c                 H    t          | fdt          j        |           i| dS )a   Draw 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`
    rm   N)r   r=   kamada_kawai_layoutrC  s     r   r   r   r
  s1    J 	44&q))4V44444r    c                 H    t          | fdt          j        |           i| dS )a  Draw 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`
    rm   N)r   r=   random_layoutrC  s     r   r   r   
  s1    H 	.. ##.v.....r    c                 H    t          | fdt          j        |           i| dS )aO  Draw 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`
    rm   N)r   r=   spectral_layoutrC  s     r   r   r   
  s1    N 	00"1%%000000r    c                 H    t          | fdt          j        |           i| dS )aV  Draw 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`
    rm   N)r   r=   r]  rC  s     r   r   r   
  s1    P 	.. ##.v.....r    c                 L    t          | fdt          j        | |          i| dS )a  Draw 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`
    rm   )nlistN)r   r=   shell_layout)r0   rN  r   s      r   r   r     s5    T 	::///:6:::::r    c                 H    t          | fdt          j        |           i| dS )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`
    rm   N)r   r=   planar_layoutrC  s     r   r   r   C  s1    R 	.. ##.v.....r    c                 H    t          | fdt          j        |           i| dS )a  Draw 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.
    rm   N)r   r=   forceatlas2_layoutrC  s     r   r   r   o  s0    " 	33%a((3F33333r    c                    ddl m}m} ddlddl}ddl}ddl}	t          |           t          |          k    rbt          | d         t                    rGj
                            |          }
|
                    ||           |
                    |           }nf	 |	                    j        j                            |           g          }n1# t"          $ r$ |	                    fd| D                       }Y nw xY w	 t          |          t          |          k    s|j        t          |          k    rR|	                    |t          |          df          }|d         |dddf<   |d	         |dddf<   |d
         |dddf<   t)           | ||          t          |                              |dddf<   n# t*          $ r ||dddf<   Y nw xY w|S )a  Apply 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   )cycleisliceNr!   c                 N    g | ]!}j         j                            |          "S r   )r   r   r*   )r   rU   rD   s     r   r   zapply_alpha.<locals>.<listcomp>  s,    NNNe*22599NNNr    r   )r   r   r   r  )r   r   r   r   )r  rU  rV  r6   matplotlib.cmr  rV  r   r   r   r:   r;   r<   r*   r   r   r   r   rT   resizer  r  )r   rX   	elem_listr"   rB   rC   rU  rV  r6   r   r+   rgba_colorsrD   s               @r   r  r    s8   J (''''''' 6{{c)nn$$F1Iv)F)F$&&D&11d###nnV,,
	((CJ$=$E$Ef$M$M#NOOKK 	 	 	((NNNNvNNN KKK	
#
 u::K((((K,<I,N,N))K#i..!1DEEK!,T!2KA!,T!2KA!,T!2KA ec+6F6F!G!GHHAAAqD # # #"AAArE#s%   3C +C?>C?C G GG)NNTr%   )NN)NrM   rK   r]   NNNNNNNNNT)NrR   r   r  NNru   NNNNNNrM   Nr]   rv   r   r   T)NrO   r   rP   rQ   NNrS   rS   NTT)Nrl   ru   r   rP   rQ   NNrS   rS   NTTrM   Nrv   T)NNN)r  rS  r  numbersr   networkxr=   __all__r   r   r   r   r   r  r	   r
   r   r   r   r   r   r   r   r   r   r   r  r   r    r   <module>r`     s   &                    , >B@
 @
 @
 @
J U U U UpL L L L^z z z z@ 
			
!g g g gTX1 X1 X1 X1 X1 X1 X1 X1| 



-r r r rp 
	 V V V Vx 
	 's s s sl)2 )2 )2X$1 $1 $1N%5 %5 %5P$/ $/ $/N'1 '1 '1T(/ (/ (/V*; *; *; *;Z)/ )/ )/X4 4 4(J J J J J Jr    