B
    î&]\ô  ã               @   sv   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d„ƒZ
d	d
„ Ze
ddd„ƒZe
ddd„ƒZe
ddd„ƒZdS )é    )ÚdivisionÚprint_functionÚabsolute_importN)Ú	decoratorÚdelaunay_plot_2dÚconvex_hull_plot_2dÚvoronoi_plot_2dc          	   K   s’   dd l m} |d kr8| ¡ }| ¡ }| |fd|i|—ŽS t|ddd„ ƒƒ }|rb| |fd|i|—ŽS z| d¡ | |fd|i|—ŽS | |¡ X d S )Nr   ÚaxZisholdc               S   s   dS )NT© r
   r
   r
   ú7lib/python3.7/site-packages/scipy/spatial/_plotutils.pyÚ<lambda>   s    z_held_figure.<locals>.<lambda>T)Zmatplotlib.pyplotZpyplotÚfigureZgcaÚgetattrZhold)ÚfuncÚobjr	   ÚkwZpltZfigZwas_heldr
   r
   r   Ú_held_figure	   s    
r   c             C   s\   d|j dd }|jdd| }|jdd| }|  |d |d ¡ |  |d |d ¡ d S )Ngš™™™™™¹?r   )Úaxisé   )ÚptpÚminÚmaxZset_xlimZset_ylim)r	   ÚpointsZmarginZxy_minZxy_maxr
   r
   r   Ú_adjust_bounds   s
    r   c             C   sX   | j jd dkrtdƒ‚| j j\}}| ||d¡ | ||| j ¡ ¡ t|| j ƒ |j	S )a  
    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()

    r   é   z!Delaunay triangulation is not 2-DÚo)
r   ÚshapeÚ
ValueErrorÚTÚplotZtriplotÚ	simplicesÚcopyr   r   )Ztrir	   ÚxÚyr
   r
   r   r   &   s    +c                sˆ   ddl m} ˆ jjd dkr$tdƒ‚| ˆ jdd…df ˆ jdd…df d¡ ‡ fdd	„ˆ jD ƒ}| ||d
dd¡ t|ˆ jƒ |j	S )aç  
    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()

    r   )ÚLineCollectionr   r   zConvex hull is not 2-DNr   c                s   g | ]}ˆ j | ‘qS r
   )r   )Ú.0Úsimplex)Úhullr
   r   ú
<listcomp>Ž   s    z'convex_hull_plot_2d.<locals>.<listcomp>ÚkÚsolid)ÚcolorsÚ	linestyle)
Úmatplotlib.collectionsr$   r   r   r   r   r    Úadd_collectionr   r   )r'   r	   r$   Zline_segmentsr
   )r'   r   r   ]   s    +*
c          	   K   s  ddl m} | jjd dkr$tdƒ‚| dd¡rj| dd	¡}|j| jd	d	…df | jd	d	…df d
|d | dd¡r | | jd	d	…df | jd	d	…df d¡ | dd¡}| dd¡}| dd¡}| jjdd}| jj	dd}	g }
g }xðt
| j| jƒD ]Þ\}}t |¡}t |dk¡r,|
 | j| ¡ qø||dk d }| j|d  | j|d   }|tj |¡ }t |d  |d g¡}| j| jdd}t t || |¡¡| }| j| ||	 ¡   }| | j| |g¡ qøW | ||
|||dd¡ | |||||dd¡ t|| jƒ |jS )a¼  
    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()

    r   )r$   r   r   zVoronoi diagram is not 2-DZshow_pointsTÚ
point_sizeNÚ.)Z
markersizeZshow_verticesr   Úline_colorsr)   Ú
line_widthg      ð?Ú
line_alpha)r   r*   )r+   ZlwZalphar,   Zdashed)r-   r$   r   r   r   Úgetr   ZverticesZmeanr   ÚzipZridge_pointsZridge_verticesÚnpZasarrayÚallÚappendZlinalgZnormZarrayZsignÚdotr   r.   r   r   )Zvorr	   r   r$   r/   r1   r2   r3   ÚcenterZ	ptp_boundZfinite_segmentsZinfinite_segmentsZpointidxr&   ÚiÚtÚnZmidpointÚ	directionZ	far_pointr
   r
   r   r   —   sN    =.*


)N)N)N)N)Z
__future__r   r   r   Znumpyr6   Zscipy._lib.decoratorr   Z
_decoratorÚ__all__r   r   r   r   r   r
   r
   r
   r   Ú<module>   s   
69