
\c           @   ss  d  Z  d d l Z d d l m Z m Z m Z m Z m Z d Z	 d d d d d	 d
 d d d d d d g Z
 d d d d  Z d e d  Z d d d d d d d d d d d d  Z d d d d d d d d d e d d  Z d d d d d d d d  Z d d d  d d d d d d e d! 
 Z d"   Z d#   Z d$   Z d%   Z d&   Z d' d(  Z d)   Z d*   Z d S(+   s   
**********
Matplotlib
**********

Draw networks with matplotlib (pylab).

See Also
--------

matplotlib:     http://matplotlib.sourceforge.net/

pygraphviz:     http://networkx.lanl.gov/pygraphviz/

iN(   t   shell_layoutt   circular_layoutt   spectral_layoutt   spring_layoutt   random_layouts   Aric Hagberg (hagberg@lanl.gov)t   drawt   draw_networkxt   draw_networkx_nodest   draw_networkx_edgest   draw_networkx_labelst   draw_networkx_edge_labelst   draw_circulart   draw_randomt   draw_spectralt   draw_springt
   draw_shellt   draw_graphvizc   	      K   s9  y d d l  j } Wn5 t k
 r2 t d   n t k
 rJ d GH  n X| j   } | j d  | d k r | j   d k r | j d  } q | j	   } n  | j
   } | j d d  } | d k	 r | j |  n  y1 t |  d	 | d
 | | | j   | j   Wn | j |    n X| j |  d S(   s  Draw the graph G with Matplotlib (pylab).

    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 networkx.layout for functions that compute node positions.

    ax : Matplotlib Axes object, optional
       Draw the graph in specified Matplotlib axes.

    hold : bool, optional
       Set the Matplotlib hold state.  If True subsequent draw
       commands will be added to the current 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.

    Good alternatives are:

    With pylab:

    >>> import pylab as P #
    >>> import networkx as nx
    >>> G=nx.dodecahedral_graph()
    >>> nx.draw(G)  # networkx draw()
    >>> P.draw()    # pylab draw()

    With pyplot

    >>> import matplotlib.pyplot as plt
    >>> import networkx as nx
    >>> G=nx.dodecahedral_graph()
    >>> nx.draw(G)  # networkx draw()
    >>> plt.draw()  # pyplot draw()

    Also see the NetworkX drawing examples at
    http://networkx.lanl.gov/gallery.html
    iNs   Matplotlib required for draw()s!   Matplotlib unable to open displayt   wi    i   t   holdt   post   ax(   i    i    i   i   (   t   matplotlib.pylabt   pylabt   ImportErrort   RuntimeErrort   gcft   set_facecolort   Nonet   _axstackt   add_axest   gcat   isholdt   popR   R   t   set_axis_offt   draw_if_interactive(	   t   GR   R   R   t   kwdsR   t   cft   bt   h(    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR   '   s4    H
c         K   s   y d d l  j } Wn5 t k
 r2 t d   n t k
 rJ d GH  n X| d k rl t j j |   } n  t |  | |  } t	 |  | |  } | r t
 |  | |  n  | j   d S(   s  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 networkx.layout for functions that compute node positions.

    with_labels :  bool, optional (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, optional (default G.nodes())
       Draw only specified nodes

    edgelist : list, optional (default=G.edges())
       Draw only specified edges

    node_size : scalar or array, optional (default=300)
       Size of nodes.  If an array is specified it must be the
       same length as nodelist.

    node_color : color string, or array of floats, (default='r')
       Node color. 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.

    node_shape :  string, optional (default='o')
       The shape of the node.  Specification is as matplotlib.scatter
       marker, one of 'so^>v<dph8'.

    alpha : float, optional (default=1.0)
       The node transparency

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

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

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

    width : float, optional (default=1.0)
       Line width of edges

    edge_color : color string, or array of floats (default='r')
       Edge color. Can be a single color format string,
       or a sequence of colors with the same length as edgelist.
       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 (default=None)
       Colormap for mapping intensities of edges

    edge_vmin,edge_vmax : floats, optional (default=None)
       Minimum and maximum for edge colormap scaling

    style : string, optional (deafult='solid')
       Edge line style (solid|dashed|dotted,dashdot)

    labels : dictionary, optional (deafult=None)
       Node labels in a dictionary keyed by node of text labels

    font_size : int, optional (default=12)
       Font size for text labels

    font_color : string, optional (default='k' black)
       Font color string

    font_weight : string, optional (default='normal')
       Font weight

    font_family : string, optional (default='sans-serif')
       Font family

    label : string, optional
        Label for graph legend

    Examples
    --------
    >>> G=nx.dodecahedral_graph()
    >>> nx.draw(G)
    >>> nx.draw(G,pos=nx.spring_layout(G)) # use spring layout

    >>> import pylab
    >>> limits=pylab.axis('off') # turn of axis

    Also see the NetworkX drawing examples at
    http://networkx.lanl.gov/gallery.html

    See Also
    --------
    draw()
    draw_networkx_nodes()
    draw_networkx_edges()
    draw_networkx_labels()
    draw_networkx_edge_labels()
    iNs   Matplotlib required for draw()s!   Matplotlib unable to open display(   R   R   R   R   R   t   nxt   drawingR   R   R   R	   R"   (   R#   R   t   with_labelsR$   R   t   node_collectiont   edge_collection(    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR      s    pi,  t   rt   og      ?c         K   s  y d d l  j } d d l } Wn5 t k
 r> t d   n t k
 rV d GH  n X|
 d k rr | j   }
 n  | d k r |  j   } n  | s t |  d k r d Sy* | j	 g  | D] } | | ^ q  } WnE t
 k
 r } t j d |   n  t k
 rt j d   n X|
 j | d d  d f | d d  d f d	 | d
 | d | d | d | d |	 d | d | d | 	} | j |  | j d  | S(   s  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.
       If not specified a spring layout positioning will be computed.
       See networkx.layout for functions that compute node positions.

    ax : Matplotlib Axes object, optional
       Draw the graph in the specified Matplotlib axes.

    nodelist : list, optional
       Draw only specified nodes (default G.nodes())

    node_size : scalar or array
       Size of nodes (default=300).  If an array is specified it must be the
       same length as nodelist.

    node_color : color string, or array of floats
       Node color. Can be a single color format string (default='r'),
       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.

    node_shape :  string
       The shape of the node.  Specification is as matplotlib.scatter
       marker, one of 'so^>v<dph8' (default='o').

    alpha : float
       The node transparency (default=1.0)

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

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

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

    label : [None| string]
       Label for legend

    Examples
    --------
    >>> G=nx.dodecahedral_graph()
    >>> nodes=nx.draw_networkx_nodes(G,pos=nx.spring_layout(G))

    Also see the NetworkX drawing examples at
    http://networkx.lanl.gov/gallery.html

    See Also
    --------
    draw()
    draw_networkx()
    draw_networkx_edges()
    draw_networkx_labels()
    draw_networkx_edge_labels()
    iNs   Matplotlib required for draw()s!   Matplotlib unable to open displayi    s   Node %s has no position.s   Bad value in node positions.i   t   st   ct   markert   cmapt   vmint   vmaxt   alphat
   linewidthst   labeli   (   R   R   t   numpyR   R   R   R   t   nodest   lent   asarrayt   KeyErrorR(   t   NetworkXErrort
   ValueErrort   scattert   scit
   set_zorder(   R#   R   t   nodelistt	   node_sizet
   node_colort
   node_shapeR5   R2   R3   R4   R   R6   R7   R$   R   R8   t   vt   xyt   eR+   (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR     sB    O*/	t   kt   solidc   5      K   s  y` d d l  } d d l j } d d l j } d d l m } m } d d l m	 } d d l
 } Wn5 t k
 r t d   n t k
 r d GH  n X|
 d k r | j   }
 n  | d k r |  j   } n  | s t |  d k r d S| j g  | D]" } | | d | | d f ^ q  } | j |  s>| f } n | } | j |  rd| j |  rdt |  t |  k rd| j g  | D] } | j |  ^ q rt g  | D] } | j | |  ^ q } q| j g  | D] } | j |  ^ q rU| j g  | D]' } | j |  o1t |  d k ^ q rLt |  } qad } qt d   nE | j |  st |  d k r| j | |  f } n t d   | | d | d | d d d | d |
 j } | j d  | j |  |
 j |  | j |  r| j |  n  | d k r| d k	 rLt | |  sLt  n  | j  | j |   | j! |  | d k	 s|	 d k	 r| j" | |	  n
 | j#   | j$ |  n  d } |  j%   ri| ri| } g  } d } x | D]\ } }  | \ }! }" |  \ }# }$ |# |! }% |$ |" }& | j& t' |% d |& d   }' |' d k rPqn  |% d k rs|# }( |& | |" }) n  |& d k r|$ }) |% | |! }( nH | j( |& |%  }* | |' | j) |*  |! }( | |' | j* |*  |" }) | j+ |( |) f |# |$ f f  qW| | d | d g  | D] }+ d
 |+ ^ qd d d |
 j } | j d  | j |  |
 j |  n  | j, | j- | d d  d d  d f   }, | j. | j- | d d  d d  d f   }- | j, | j- | d d  d d  d f   }. | j. | j- | d d  d d  d f   }/ |- |, }0 |/ |. }1 d |0 d |1 }2 }3 |, |2 |. |3 f |- |2 |/ |3 f f }4 |
 j/ |4  |
 j0   | S(   s  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.
       If not specified a spring layout positioning will be computed.
       See networkx.layout for functions that compute node positions.

    edgelist : collection of edge tuples
       Draw only specified edges(default=G.edges())

    width : float
       Line width of edges (default =1.0)

    edge_color : color string, or array of floats
       Edge color. Can be a single color format string (default='r'),
       or a sequence of colors with the same length as edgelist.
       If numeric values are specified they will be mapped to
       colors using the edge_cmap and edge_vmin,edge_vmax parameters.

    style : string
       Edge line style (default='solid') (solid|dashed|dotted,dashdot)

    alpha : float
       The edge transparency (default=1.0)

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

    edge_vmin,edge_vmax : floats
       Minimum and maximum for edge colormap scaling (default=None)

    ax : Matplotlib Axes object, optional
       Draw the graph in the specified Matplotlib axes.

    arrows : bool, optional (default=True)
       For directed graphs, if True draw arrowheads.

    label : [None| string]
       Label for legend

    Notes
    -----
    For directed graphs, "arrows" (actually just thicker stubs) are drawn
    at the head end.  Arrows can be turned off with keyword arrows=False.
    Yes, it is ugly but drawing proper arrows with Matplotlib this
    way is tricky.

    Examples
    --------
    >>> G=nx.dodecahedral_graph()
    >>> edges=nx.draw_networkx_edges(G,pos=nx.spring_layout(G))

    Also see the NetworkX drawing examples at
    http://networkx.lanl.gov/gallery.html

    See Also
    --------
    draw()
    draw_networkx()
    draw_networkx_nodes()
    draw_networkx_labels()
    draw_networkx_edge_labels()
    iN(   t   colorConvertert   Colormap(   t   LineCollections   Matplotlib required for draw()s!   Matplotlib unable to open displayi    i   i   i   s8   edge_color must consist of either color names or numberss\   edge_color must be a single color or list of exactly m colors where m is the number or edgest   colorsR6   t   antialiasedst	   linestylet   transOffsetg      ?g      ?i   g?(   i   i   (   i   g      ?(   i   (1   t
   matplotlibR   R   t   matplotlib.cbookt   cbookt   matplotlib.colorsRK   RL   t   matplotlib.collectionsRM   R8   R   R   R   R   t   edgesR:   R;   t   iterablet   is_string_liket   alltruet   tuplet   to_rgbaR>   t	   transDataRA   t	   set_labelt   add_collectiont
   is_numliket	   set_alphat
   isinstancet   AssertionErrort	   set_arrayt   set_cmapt   set_climt	   autoscaleR@   t   is_directedt   sqrtt   floatt   arctan2t   cost   sint   appendt   amint   ravelt   amaxt   update_datalimt   autoscale_view(5   R#   R   t   edgelistt   widtht
   edge_colort   styleR5   t	   edge_cmapt	   edge_vmint	   edge_vmaxR   t   arrowsR7   R$   RR   R   t   cbRK   RL   RM   R8   RH   t   edge_post   lwR0   t   edge_colorsR,   t   arrow_collectiont   arrow_colorst   a_post   pt   srct   dstt   x1t   y1t   x2t   y2t   dxt   dyt   dt   xat   yat   thetat   wwt   minxt   maxxt   minyt   maxyR   R'   t   padxt   padyt   corners(    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR     s    S8	"(	#	4	!	


!#	1111

(
i   s
   sans-serift   normalc	         K   sk  y" d d l  j }
 d d l j } Wn5 t k
 rA t d   n t k
 rY d GH  n X| d k ru |
 j   } n  | d k r t d   |  j	   D  } n  |	 j
 d d  } |	 j
 d d  } i  } x | j   D] \ } } | | \ } } | j |  st |  } n  | j | | | d	 | d
 | d | d | d | d | d | j d t } | | | <q W| S(   sl  Draw node labels on the graph G.

    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 networkx.layout for functions that compute node positions.

    font_size : int
       Font size for text labels (default=12)

    font_color : string
       Font color string (default='k' black)

    font_family : string
       Font family (default='sans-serif')

    font_weight : string
       Font weight (default='normal')

    alpha : float
       The text transparency (default=1.0)

    ax : Matplotlib Axes object, optional
       Draw the graph in the specified Matplotlib axes.


    Examples
    --------
    >>> G=nx.dodecahedral_graph()
    >>> labels=nx.draw_networkx_labels(G,pos=nx.spring_layout(G))

    Also see the NetworkX drawing examples at
    http://networkx.lanl.gov/gallery.html


    See Also
    --------
    draw()
    draw_networkx()
    draw_networkx_nodes()
    draw_networkx_edges()
    draw_networkx_edge_labels()
    iNs   Matplotlib required for draw()s!   Matplotlib unable to open displayc         s   s   |  ] } | | f Vq d  S(   N(    (   t   .0t   n(    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pys	   <genexpr>  s    t   horizontalalignmentt   centert   verticalalignmentt   sizet   colort   familyt   weightt	   transformt   clip_on(   R   R   RS   RT   R   R   R   R   t   dictR9   t   gett   itemsRY   t   strt   textR]   t   True(   R#   R   t   labelst	   font_sizet
   font_colort   font_familyt   font_weightR5   R   R$   R   R|   R   R   t
   text_itemsR   R7   t   xt   yt   t(    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR	   t  s>    9		g      ?i
   c   !      K   s  y. d d l  j } d d l j } d d l } Wn5 t k
 rM t d   n t k
 re d GH  n X|
 d k r | j   }
 n  | d k r t	 d   |  j
 d t  D  } n | } i  } x| j   D]\ \ } } } | | \ } } | | \ } } | | | d | | | | d | } } | r| j | | | |  d | j d	 } | d
 k rr| d 8} n  | d k  r| d 7} n  | j | | f  } |
 j j | j | f  | j d!   d } n d } |	 d k rt	 d d d d" d d#  }	 n  | j |  st |  } n  | j d d  } | j d d  } |
 j | | | d | d | d | d | d | d | d | d |
 j d |	 d d d  t }  |  | | | f <q W| S($   s  Draw edge labels.

    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 networkx.layout for functions that compute node positions.

    ax : Matplotlib Axes object, optional
       Draw the graph in the specified Matplotlib axes.

    alpha : float
       The text transparency (default=1.0)

    edge_labels : dictionary
       Edge labels in a dictionary keyed by edge two-tuple of text
       labels (default=None). Only labels for the keys in the dictionary
       are drawn.

    label_pos : float
       Position of edge label along edge (0=head, 0.5=center, 1=tail)

    font_size : int
       Font size for text labels (default=12)

    font_color : string
       Font color string (default='k' black)

    font_weight : string
       Font weight (default='normal')

    font_family : string
       Font family (default='sans-serif')

    bbox : Matplotlib bbox
       Specify text box shape and colors.

    clip_on : bool
       Turn on clipping at axis boundaries (default=True)

    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
    http://networkx.lanl.gov/gallery.html

    See Also
    --------
    draw()
    draw_networkx()
    draw_networkx_nodes()
    draw_networkx_edges()
    draw_networkx_labels()
    iNs   Matplotlib required for draw()s!   Matplotlib unable to open displayc         s   s*   |  ]  \ } } } | | f | f Vq d  S(   N(    (   R   t   uRF   R   (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pys	   <genexpr>)  s    t   datag      ?g       @ih  iZ   i   ii   i   i    g        t   boxstylet   roundt   ect   fcR   R   R   R   R   R   R   t   rotationR   t   bboxt   zorderR   (   i   i   (   g      ?g      ?g      ?(   g      ?g      ?g      ?(   R   R   RS   RT   R8   R   R   R   R   R   RW   R   R   Rk   t   pit   arrayR]   t   transform_anglest   reshapeRY   R   R   R   (!   R#   R   t   edge_labelst	   label_posR   R   R   R   R5   R   R   t   rotateR$   R   R|   R8   R   R   t   n1t   n2R7   R   R   R   R   R   R   t   angleRG   t   trans_angleR   R   R   (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR
     sj    H%)		c         K   s   t  |  t |   |  d S(   s(   Draw the graph G with a circular layout.N(   R   R   (   R#   t   kwargs(    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR   _  s    c         K   s   t  |  t |   |  d S(   s&   Draw the graph G with a random layout.N(   R   R   (   R#   R   (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR   c  s    c         K   s   t  |  t |   |  d S(   s(   Draw the graph G with a spectral layout.N(   R   R   (   R#   R   (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR   g  s    c         K   s   t  |  t |   |  d S(   s&   Draw the graph G with a spring layout.N(   R   R   (   R#   R   (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR   k  s    c         K   sH   | j  d d  } | d k r( | d =n  t |  t |  d | |  d S(   s&   Draw networkx graph with shell layout.t   nlistN(   R   R   R   R    (   R#   R   R   (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR   o  s    
t   neatoc         K   s)   t  j j |  |  } t |  | |  d S(   s)   Draw networkx graph with graphviz layout.N(   R(   R)   t   graphviz_layoutR   (   R#   t   progR   R   (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyR   v  s    c         K   s   t  |  | |  d S(   s6   For backward compatibility; use draw or draw_networkx.N(   R   (   R#   R   R$   (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyt   draw_nx{  s    c         C   sY   d d l  m } y/ d d  l } | j d d t d d  l } Wn | d   n Xd  S(   Ni(   t   SkipTestt   PSt   warns   matplotlib not available(   t   noseR   RR   t   uset   FalseR   (   t   moduleR   t   mplR   (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyt   setup_module  s    (   t   __doc__t   networkxR(   t   networkx.drawing.layoutR    R   R   R   R   t
   __author__t   __all__R   R   R   R   R   R   R	   R
   R   R   R   R   R   R   R   R   (    (    (    sQ   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/drawing/nx_pylab.pyt   <module>   s   (	hrZ						