ó
x\c           @   s  d  d l  m Z d  d l Z d  d l m Z m Z m Z m Z d  d l	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z d  d l m Z m Z d	 d d e d
 d d d d d 	 Z d   Z d d d d  Z e
 d d d d  d d d d d   Z d d d d  Z e
 d d d d  e
 d d d d d d  d d d e d d e d e d 	   Z d d d  Z d d   Z d S(!   i˙˙˙˙(   t   divisionN(   t   lmapt   lranget   ranget   zip(   t   deprecate_kwarg(   t   notna(   t   pprint_thing(   t   _get_standard_colors(   t   _set_ticks_propst	   _subplotsg      ŕ?t   histt   .gŠ?c
   #   
   K   s7  |  j    } | j j } | | } t d | d | d | d t  \ } } | j d d d d  t |  } t |  } | p i  } | p i  } |
 j d d	  g  } xu | j D]j } | | j	 | | j	 } t
 j |  t
 j |  } } | | |	 d
 } | j | | | | f  qŻ Wxćt t |  | j  D]Ě\ } } x˝t t |  | j  D]Ł\ } } | | | f } | | k r<| | j	 | | j	 } | d k rş| j | |  nn | d k r(d d l m } | } | |  } t
 j | j   | j   d  } | j | | j |  |  n  | j | |  nf | | | | @j	 } | j | | | | | | d | d | |
 | j | |  | j | |  | j |  | j |  | d k rŰ| j j t  n  | | d k r[| j j t  q[q[Wq6Wt | j  d k r| d } | d d j j   }  |  | d |  k |  | d k @}  |  | d | d | d }! | d d j    }" |! |" d |" d |" d }! | d d j j! |!  t
 j" |  |  j# t$  k  rö|  j# t$  }  n  | d d j j% |   n  t& | d d d d d d d d | S(   s  
    Draw a matrix of scatter plots.

    Parameters
    ----------
    frame : DataFrame
    alpha : float, optional
        amount of transparency applied
    figsize : (float,float), optional
        a tuple (width, height) in inches
    ax : Matplotlib axis object, optional
    grid : bool, optional
        setting this to True will show the grid
    diagonal : {'hist', 'kde'}
        pick between 'kde' and 'hist' for
        either Kernel Density Estimation or Histogram
        plot in the diagonal
    marker : str, optional
        Matplotlib marker type, default '.'
    hist_kwds : other plotting keyword arguments
        To be passed to hist function
    density_kwds : other plotting keyword arguments
        To be passed to kernel density estimate plot
    range_padding : float, optional
        relative extension of axis range in x and y
        with respect to (x_max - x_min) or (y_max - y_min),
        default 0.05
    kwds : other plotting keyword arguments
        To be passed to scatter function

    Examples
    --------
    >>> df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D'])
    >>> scatter_matrix(df, alpha=0.2)
    t   naxest   figsizet   axt   squeezet   wspacei    t   hspacet
   edgecolorst   noneg       @R   t   kdet   densityi˙˙˙˙(   t   gaussian_kdeič  t   markert   alphai   t
   xlabelsizei   t   xrotiZ   t
   ylabelsizet   yrot(   R   R   ('   t   _get_numeric_datat   columnst   sizeR
   t   Falset   subplots_adjustR   t   _get_marker_compatt
   setdefaultt   valuest   npt   mint   maxt   appendR   R   R   t   scipy.statsR   t   linspacet   plott   evaluatet   set_xlimt   scattert   set_ylimt
   set_xlabelt
   set_ylabelt   yaxist   set_visiblet   xaxist   lent   get_majorticklocst   get_ylimt	   set_tickst   allt   astypet   intt   set_ticklabelsR	   (#   t   frameR   R   R   t   gridt   diagonalR   t   density_kwdst	   hist_kwdst   range_paddingt   kwdst   dft   nR   t   figt   axest   maskt   boundaries_listt   aR%   t   rmin_t   rmax_t
   rdelta_extt   it   jt   bR   t   yt   gkdet   indt   commont   lim1t   locst   adjt   lim0(    (    s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt   scatter_matrix   sn    '
%%!
""c         C   s&   d d  l  j } |  | j k r" d S|  S(   Ni˙˙˙˙t   o(   t   matplotlib.linest   linest   lineMarkers(   R   t   mlines(    (    s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyR#      s    c         K   sL  d d l  j } d d l j } d   } t |   }	 |  | j   }
 |  | } |  j | d d j |  } | d k r | j	 d d d g d d d g  } n  i  } t
 d t |
  d	 | d
 d d |  } x |
 D] } g  g  g | | <qŇ Wt |  j  d } t j g  g  t |  D]! } d t j | t |  ^ qD]$ } t j |  t j |  f ^ q: } xŞ t |	  D] } | j | j } t j t j | d d d d d } | | j d d  | j   } | j | } | | d j | d  | | d j | d  qtWxS t |
  D]E \ } } | j | | d | | d d | | d t |  | q!W| j   | j | j d! d d d d  x˘t  | | j  D]\ } } | j | j | d d d d  | d d k  r/| d d k  r/| j! | d d | d d | d d d d d d qŠ| d d k  r| d d k r| j! | d d | d d | d d d d d d qŠ| d d k rß| d d k  rß| j! | d d | d d | d d d d d d qŠ| d d k rŠ| d d k rŠ| j! | d d | d d | d d d d d d qŠqŠW| j" d   | S("   ss	  
    Plot a multidimensional dataset in 2D.

    Each Series in the DataFrame is represented as a evenly distributed
    slice on a circle. Each data point is rendered in the circle according to
    the value on each Series. Highly correlated `Series` in the `DataFrame`
    are placed closer on the unit circle.

    RadViz allow to project a N-dimensional data set into a 2D space where the
    influence of each dimension can be interpreted as a balance between the
    influence of all dimensions.

    More info available at the `original article
    <http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.135.889>`_
    describing RadViz.

    Parameters
    ----------
    frame : `DataFrame`
        Pandas object holding the data.
    class_column : str
        Column name containing the name of the data point category.
    ax : :class:`matplotlib.axes.Axes`, optional
        A plot instance to which to add the information.
    color : list[str] or tuple[str], optional
        Assign a color to each category. Example: ['blue', 'green'].
    colormap : str or :class:`matplotlib.colors.Colormap`, default None
        Colormap to select colors from. If string, load colormap with that
        name from matplotlib.
    kwds : optional
        Options to pass to matplotlib scatter plotting method.

    Returns
    -------
    axes : :class:`matplotlib.axes.Axes`

    See Also
    --------
    pandas.plotting.andrews_curves : Plot clustering visualization.

    Examples
    --------
    .. plot::
        :context: close-figs

        >>> df = pd.DataFrame({
        ...         'SepalLength': [6.5, 7.7, 5.1, 5.8, 7.6, 5.0, 5.4, 4.6,
        ...                         6.7, 4.6],
        ...         'SepalWidth': [3.0, 3.8, 3.8, 2.7, 3.0, 2.3, 3.0, 3.2,
        ...                        3.3, 3.6],
        ...         'PetalLength': [5.5, 6.7, 1.9, 5.1, 6.6, 3.3, 4.5, 1.4,
        ...                         5.7, 1.0],
        ...         'PetalWidth': [1.8, 2.2, 0.4, 1.9, 2.1, 1.0, 1.5, 0.2,
        ...                        2.1, 0.2],
        ...         'Category': ['virginica', 'virginica', 'setosa',
        ...                      'virginica', 'virginica', 'versicolor',
        ...                      'versicolor', 'setosa', 'virginica',
        ...                      'setosa']
        ...     })
        >>> rad_viz = pd.plotting.radviz(df, 'Category')  # doctest: +SKIP
    i˙˙˙˙Nc         S   s(   t  |   } t |   } |  | | | S(   N(   R'   R(   (   t   seriesRK   RQ   (    (    s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt	   normalizeÓ   s    t   axisi   t   xlimt   ylimt
   num_colorst   colormapt
   color_typet   randomt   colorg       @i   i    t   labelg        t   radiusg      đ?t	   facecolorR   g?t   grayt   hat   rightt   vat   topR    t   smallt   bottomt   leftt   equal(   g        g        (#   t   matplotlib.pyplott   pyplott   matplotlib.patchest   patchesR6   t   drop_duplicatest   dropt   applyt   Nonet   gcaR   R   R&   t   arrayR   t   pit   floatt   cost   sint   ilocR%   t   repeatt   expand_dimst   sumt   iatR)   t	   enumerateR/   R   t   legendt	   add_patcht   CircleR   t   textRb   (   R>   t   class_columnR   Ri   Rf   RD   t   pltRy   Ra   RF   t   classest	   class_colRE   t   to_plott   colorst   klst   mRO   t   tt   st   rowt   row_RR   t   xyt   name(    (    s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt   radviz   s\    >	
'	\' )
"" " " " "t   old_arg_namet   datat   new_arg_nameR>   iČ   c      	      sÄ  d d l  m   m } d d l j }   f d   }	 t |   }
 |  | } |  | j   } |  j | d d } t j	 | | |  } t
   } t d t |  d | d	 d
 d |  } t t | |   } | d k rň | j d | | f  } n  xą t |
  D]Ł } | j | j } |	 |  } | |  } | j | } t |  } | | k r| j |  | j | | d | | d | | q˙ | j | | d | | | q˙ W| j d d  | j   | S(   s>  
    Generates a matplotlib plot of Andrews curves, for visualising clusters of
    multivariate data.

    Andrews curves have the functional form:

    f(t) = x_1/sqrt(2) + x_2 sin(t) + x_3 cos(t) +
           x_4 sin(2t) + x_5 cos(2t) + ...

    Where x coefficients correspond to the values of each dimension and t is
    linearly spaced between -pi and +pi. Each row of frame then corresponds to
    a single curve.

    Parameters
    ----------
    frame : DataFrame
        Data to be plotted, preferably normalized to (0.0, 1.0)
    class_column : Name of the column containing class names
    ax : matplotlib axes object, default None
    samples : Number of points to plot in each curve
    color : list or tuple, optional
        Colors to use for the different classes
    colormap : str or matplotlib colormap object, default None
        Colormap to select colors from. If string, load colormap with that name
        from matplotlib.
    kwds : keywords
        Options to pass to matplotlib plotting method

    Returns
    -------
    ax : Matplotlib axis object

    i˙˙˙˙(   t   sqrtR   Nc            s      f d   } | S(   Nc            sě     d } |  d  } t  j t  j    d  } | j t | j d d  d  t  j d | j d  d } t  j | |   } | t  j	 | d  d   d t  j
 f t  j |  | d  d   d t  j
 f t  j |  d d 7} | S(   Ni    g       @i   i   Rb   (   R&   t   deletet   copyt   resizeR<   R    t   aranget   shapet   outerR   t   newaxisR   R   (   R   t   x1t   resultt   coeffst	   harmonicst	   trig_args(   t
   amplitudesR    (    s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt   f8  s    
!/*
(    (   R­   RŽ   (   R    (   R­   s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt   function7  s    Rb   i   Re   Rf   Rg   Rh   Ri   Rc   Rj   t   locs   upper right(   t   mathR    R   Rv   Rw   R6   Rz   R{   R&   R+   t   setR   t   dictR   R}   R~   R   R   R%   R   R   t   addR,   R   R?   (   R>   R   R   t   samplesRi   Rf   RD   R   R   RŻ   RF   R   R   RE   R   t   used_legendst   color_valuesR   RO   R   RŽ   RR   R   Rj   (    (   R    s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt   andrews_curves  s8    $
		&!
i2   iô  c         K   sŘ  d d l  } d d l j } t |  j  } g  t |  D] } | j | |  ^ q7 }	 t j g  |	 D] }
 t j	 |
  ^ qb  } t j g  |	 D] }
 t j
 |
  ^ q  } t j g  |	 D]  }
 t |
  t |
  d ^ q¸  } | d k rü | j   } n  t |  } g  } | j d d d  } | j d  | j |  | j | | |  | j d d d  } | j d  | j |  | j | | |  | j d d d  } | j d  | j |  | j | | |  | j d d d  } | j d	  | j |  | j | |  | j d d d
  } | j d  | j |  | j | |  | j d d d  } | j d  | j |  | j | |  x@ | D]8 } | j | j   d d | j | j   d d qW| S(   sü  
    Bootstrap plot on mean, median and mid-range statistics.

    The bootstrap plot is used to estimate the uncertainty of a statistic
    by relaying on random sampling with replacement [1]_. This function will
    generate bootstrapping plots for mean, median and mid-range statistics
    for the given number of samples of the given size.

    .. [1] "Bootstrapping (statistics)" in     https://en.wikipedia.org/wiki/Bootstrapping_%28statistics%29

    Parameters
    ----------
    series : pandas.Series
        Pandas Series from where to get the samplings for the bootstrapping.
    fig : matplotlib.figure.Figure, default None
        If given, it will use the `fig` reference for plotting instead of
        creating a new one with default parameters.
    size : int, default 50
        Number of data points to consider during each sampling. It must be
        greater or equal than the length of the `series`.
    samples : int, default 500
        Number of times the bootstrap procedure is performed.
    **kwds :
        Options to pass to matplotlib plotting method.

    Returns
    -------
    fig : matplotlib.figure.Figure
        Matplotlib figure

    See Also
    --------
    pandas.DataFrame.plot : Basic plotting for DataFrame objects.
    pandas.Series.plot : Basic plotting for Series objects.

    Examples
    --------

    .. plot::
            :context: close-figs

            >>> s = pd.Series(np.random.uniform(size=100))
            >>> fig = pd.plotting.bootstrap_plot(s)  # doctest: +SKIP
    i˙˙˙˙Ng      ŕ?i   i   i   t   Samplei   t   Meani   t   Mediani   t   Midranget   fontsizei   (   Rh   Rv   Rw   t   listR%   R   t   sampleR&   R   t   meant   medianR'   R(   R}   t   figureR   t   add_subplotR1   R)   R,   R   t   setpt   get_xticklabelst   get_yticklabels(   R`   RG   R    Rľ   RD   Rh   R   R   t   _t	   samplingst   samplingt   meanst   medianst	   midrangest   xRH   t   ax1t   ax2t   ax3t   ax4t   ax5t   ax6Rb   (    (    s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt   bootstrap_plotk  sP    .+++	-R   Ri   t
   stackleveli   c      	   K   sŕ  |	 d k r# i d d 6d d 6}	 n  d d l j } t |   } |  | j   } |  | } | d k r| |  j | d d } n
 |  | } t   } t | j  } | t k rć t	 j
 t	 j t | j    sÚ t d   n  | j } ni | d k	 rCt	 j
 t	 j |   st d	   n! t |  | k r:t d
   n  | } n t |  } | d k rj| j   } n  t d t |  d | d d d |  } |
 r˛t |  } t |  } n  t t | |   } x t |  D] } | j | j } | j | } t |  } | | k rB| j |  | j | | d | | d | | qÔ| j | | d | | | qÔW| rx! | D] } | j | |	  qpWn  | j |  | j | j  | j | d | d  | j d d  | j    | S(   s  Parallel coordinates plotting.

    Parameters
    ----------
    frame : DataFrame
    class_column : str
        Column name containing class names
    cols : list, optional
        A list of column names to use
    ax : matplotlib.axis, optional
        matplotlib axis object
    color : list or tuple, optional
        Colors to use for the different classes
    use_columns : bool, optional
        If true, columns will be used as xticks
    xticks : list or tuple, optional
        A list of values to use for xticks
    colormap : str or matplotlib colormap, default None
        Colormap to use for line colors.
    axvlines : bool, optional
        If true, vertical lines will be added at each xtick
    axvlines_kwds : keywords, optional
        Options to be passed to axvline method for vertical lines
    sort_labels : bool, False
        Sort class_column labels, useful when assigning colors

        .. versionadded:: 0.20.0

    kwds : keywords
        Options to pass to matplotlib plotting method

    Returns
    -------
    ax: matplotlib axis object

    Examples
    --------
    >>> from matplotlib import pyplot as plt
    >>> df = pd.read_csv('https://raw.github.com/pandas-dev/pandas/master'
                        '/pandas/tests/data/iris.csv')
    >>> pd.plotting.parallel_coordinates(
            df, 'Name',
            color=('#556270', '#4ECDC4', '#C7F464'))
    >>> plt.show()
    i   t	   linewidtht   blackRi   i˙˙˙˙NRb   s,   Columns must be numeric to be used as xtickss    xticks specified must be numerics-   Length of xticks must match number of columnsRe   Rf   Rg   Rh   Rj   i    R°   s   upper right(!   R}   Rv   Rw   R6   Rz   R{   R˛   R   t   TrueR&   R:   t   isrealRž   t
   ValueErrorR   R~   R   t   sortedRł   R   R   R   R%   R   R   R´   R,   t   axvlinet
   set_xtickst   set_xticklabelsR.   R   R?   (   R>   R   t   colsR   Ri   t   use_columnst   xticksRf   t   axvlinest   axvlines_kwdst   sort_labelsRD   R   RF   R   R   RE   Rś   t   ncolsRÍ   Rˇ   R   RO   RR   R   Rj   (    (    s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt   parallel_coordinatesĆ  s`    3

	!		&!
i   c         K   s   d d l  j } | j d | j d  |  j } | |  } | | } | d k r_ | j   } n  | j d  | j d j	 d |   | j
 | | |  | S(   s&  Lag plot for time series.

    Parameters
    ----------
    series : Time series
    lag : lag of the scatter plot, default 1
    ax : Matplotlib axis object, optional
    kwds : Matplotlib scatter method keyword arguments, optional

    Returns
    -------
    ax: Matplotlib axis object
    i˙˙˙˙Nt   cs   patch.facecolors   y(t)s   y(t + {lag})t   lag(   Rv   Rw   R$   t   rcParamsR%   R}   R~   R1   R2   t   formatR/   (   R`   Rč   R   RD   R   R   t   y1t   y2(    (    s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt   lag_plot:  s    	
c   	         sŃ  d d l  j } t |    t j |    | d k rW | j d d  f d d  } n  t j    t j   d  t	          f d	   } t j
   d } t | |  } d
 } d } | j d | t j   d d d d  | j d | t j   d d  | j d d d d  | j d | t j   d d  | j d | t j   d d d d  | j d  | j d  | j | | |  d | k rĂ| j   n  | j   | S(   s  Autocorrelation plot for time series.

    Parameters:
    -----------
    series: Time series
    ax: Matplotlib axis object, optional
    kwds : keywords
        Options to pass to matplotlib plotting method

    Returns:
    -----------
    ax: Matplotlib axis object
    i˙˙˙˙NRc   i   Rd   g      đżg      đ?i   c            s0     |     |   j    t     S(   N(   R   R   (   t   h(   t   c0R   RŔ   RF   (    s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt   rn  s    g˙î1\˙?g`ÖdL@RR   t	   linestyles   --Ri   t   greyg        R×   t   Lagt   AutocorrelationRj   (   g      đżg      đ?(   Rv   Rw   R6   R&   t   asarrayR}   R~   RŔ   R   R   R¤   R   t   axhlineR    R1   R2   R,   R   R?   (	   R`   R   RD   R   Rđ   RÍ   RR   t   z95t   z99(    (   Rď   R   RŔ   RF   s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt   autocorrelation_plotX  s0    !!)#$*
(   t
   __future__R    t   numpyR&   t   pandas.compatR   R   R   R   t   pandas.util._decoratorsR   t   pandas.core.dtypes.missingR   t   pandas.io.formats.printingR   t   pandas.plotting._styleR   t   pandas.plotting._toolsR	   R
   R}   R!   RZ   R#   R   R¸   RÔ   RŘ   Rć   Rí   Rů   (    (    (    s4   lib/python2.7/site-packages/pandas/plotting/_misc.pyt   <module>   s.   "	x	~	Y[		p