ó
î&]\c           @` sœ   d  d l  m Z m Z m Z d  d l Z d  d l m Z d d d g Z	 e d d „ ƒ Z d „  Z e d d	 „ ƒ Z e d d
 „ ƒ Z e d d „ ƒ Z d S(   i    (   t   divisiont   print_functiont   absolute_importN(   t	   decoratort   delaunay_plot_2dt   convex_hull_plot_2dt   voronoi_plot_2dc         K` s°   d d  l  j } | d  k rF | j ƒ  } | j ƒ  } |  | d | | St | d d „  ƒ ƒ  } | rw |  | d | | Sz$ | j t ƒ |  | d | | SWd  | j | ƒ Xd  S(   Ni    t   axt   isholdc           S` s   t  S(   N(   t   True(    (    (    s7   lib/python2.7/site-packages/scipy/spatial/_plotutils.pyt   <lambda>   s    (   t   matplotlib.pyplott   pyplott   Nonet   figuret   gcat   getattrt   holdR	   (   t   funct   objR   t   kwt   pltt   figt   was_held(    (    s7   lib/python2.7/site-packages/scipy/spatial/_plotutils.pyt   _held_figure	   s    c         C` sv   d | j  d d ƒ } | j d d ƒ | } | j d d ƒ | } |  j | d | d ƒ |  j | d | d ƒ d  S(   Ngš™™™™™¹?t   axisi    i   (   t   ptpt   mint   maxt   set_xlimt   set_ylim(   R   t   pointst   margint   xy_mint   xy_max(    (    s7   lib/python2.7/site-packages/scipy/spatial/_plotutils.pyt   _adjust_bounds   s
    c         C` s}   |  j  j d d k r% t d ƒ ‚ n  |  j  j \ } } | j | | d ƒ | j | | |  j j ƒ  ƒ t | |  j  ƒ | j	 S(   s  
    Plot the given Delaunay triangulation in 2-D

    Parameters
    ----------
    tri : scipy.spatial.Delaunay instance
        Triangulation to plot
    ax : matplotlib.axes.Axes instance, optional
        Axes to plot on

    Returns
    -------
    fig : matplotlib.figure.Figure instance
        Figure for the plot

    See Also
    --------
    Delaunay
    matplotlib.pyplot.triplot

    Notes
    -----
    Requires Matplotlib.

    Examples
    --------

    >>> import matplotlib.pyplot as plt
    >>> from scipy.spatial import Delaunay, delaunay_plot_2d

    The Delaunay triangulation of a set of random points:

    >>> points = np.random.rand(30, 2)
    >>> tri = Delaunay(points)

    Plot it:

    >>> _ = delaunay_plot_2d(tri)
    >>> plt.show()

    i   i   s!   Delaunay triangulation is not 2-Dt   o(
   R   t   shapet
   ValueErrort   Tt   plott   triplott	   simplicest   copyR#   R   (   t   triR   t   xt   y(    (    s7   lib/python2.7/site-packages/scipy/spatial/_plotutils.pyR   &   s    +c         C` sÇ   d d l  m } |  j j d d k r5 t d ƒ ‚ n  | j |  j d d … d f |  j d d … d f d ƒ g  |  j D] } |  j | ^ qx } | j | | d d	 d
 d ƒƒ t | |  j ƒ | j	 S(   sç  
    Plot the given convex hull diagram in 2-D

    Parameters
    ----------
    hull : scipy.spatial.ConvexHull instance
        Convex hull to plot
    ax : matplotlib.axes.Axes instance, optional
        Axes to plot on

    Returns
    -------
    fig : matplotlib.figure.Figure instance
        Figure for the plot

    See Also
    --------
    ConvexHull

    Notes
    -----
    Requires Matplotlib.


    Examples
    --------

    >>> import matplotlib.pyplot as plt
    >>> from scipy.spatial import ConvexHull, convex_hull_plot_2d

    The convex hull of a random set of points:

    >>> points = np.random.rand(30, 2)
    >>> hull = ConvexHull(points)

    Plot it:

    >>> _ = convex_hull_plot_2d(hull)
    >>> plt.show()

    i    (   t   LineCollectioni   i   s   Convex hull is not 2-DNR$   t   colorst   kt	   linestylet   solid(
   t   matplotlib.collectionsR/   R   R%   R&   R(   R*   t   add_collectionR#   R   (   t   hullR   R/   t   simplext   line_segments(    (    s7   lib/python2.7/site-packages/scipy/spatial/_plotutils.pyR   ]   s    +9#
c         K` sü  d d l  m } |  j j d d k r5 t d ƒ ‚ n  | j d t ƒ r› | j d d ƒ } | j |  j d d … d f |  j d d … d f d	 d
 | ƒn  | j d t ƒ ré | j |  j	 d d … d f |  j	 d d … d f d ƒ n  | j d d ƒ } | j d d ƒ } | j d d ƒ } |  j j
 d d ƒ } |  j j d d ƒ }	 g  }
 g  } x7t |  j |  j ƒ D] \ } } t j | ƒ } t j | d k ƒ r²|
 j |  j	 | ƒ qk| | d k d } |  j | d |  j | d } | t j j | ƒ } t j | d | d g ƒ } |  j | j
 d d ƒ } t j t j | | | ƒ ƒ | } |  j	 | | |	 j ƒ  } | j |  j	 | | g ƒ qkW| j | |
 d | d | d | d d ƒƒ | j | | d | d | d | d d ƒƒ t | |  j ƒ | j S(   s¼  
    Plot the given Voronoi diagram in 2-D

    Parameters
    ----------
    vor : scipy.spatial.Voronoi instance
        Diagram to plot
    ax : matplotlib.axes.Axes instance, optional
        Axes to plot on
    show_points: bool, optional
        Add the Voronoi points to the plot.
    show_vertices : bool, optional
        Add the Voronoi vertices to the plot.
    line_colors : string, optional
        Specifies the line color for polygon boundaries
    line_width : float, optional
        Specifies the line width for polygon boundaries
    line_alpha: float, optional
        Specifies the line alpha for polygon boundaries
    point_size: float, optional
        Specifies the size of points


    Returns
    -------
    fig : matplotlib.figure.Figure instance
        Figure for the plot

    See Also
    --------
    Voronoi

    Notes
    -----
    Requires Matplotlib.

    Examples
    --------
    Set of point:

    >>> import matplotlib.pyplot as plt
    >>> points = np.random.rand(10,2) #random

    Voronoi diagram of the points:

    >>> from scipy.spatial import Voronoi, voronoi_plot_2d
    >>> vor = Voronoi(points)

    using `voronoi_plot_2d` for visualisation:

    >>> fig = voronoi_plot_2d(vor)

    using `voronoi_plot_2d` for visualisation with enhancements:

    >>> fig = voronoi_plot_2d(vor, show_vertices=False, line_colors='orange',
    ...                 line_width=2, line_alpha=0.6, point_size=2)
    >>> plt.show()

    i    (   R/   i   i   s   Voronoi diagram is not 2-Dt   show_pointst
   point_sizeNt   .t
   markersizet   show_verticesR$   t   line_colorsR1   t
   line_widthg      ð?t
   line_alphaR   R0   t   lwt   alphaR2   R3   t   dashed(   R4   R/   R   R%   R&   t   getR	   R   R(   t   verticest   meanR   t   zipt   ridge_pointst   ridge_verticest   npt   asarrayt   allt   appendt   linalgt   normt   arrayt   signt   dotR   R5   R#   R   (   t   vorR   R   R/   R:   R>   R?   R@   t   centert	   ptp_boundt   finite_segmentst   infinite_segmentst   pointidxR7   t   it   tt   nt   midpointt	   directiont	   far_point(    (    s7   lib/python2.7/site-packages/scipy/spatial/_plotutils.pyR   —   sN    =B<" #

(   t
   __future__R    R   R   t   numpyRJ   t   scipy._lib.decoratorR   t
   _decoratort   __all__R   R   R#   R   R   R   (    (    (    s7   lib/python2.7/site-packages/scipy/spatial/_plotutils.pyt   <module>   s   	69