
W[c           @   s$  d  d l  m Z d  d l m Z d  d l m Z d  d l Z d  d l m Z d  d l	 Z
 d  d l Z d  d l m Z d  d l Z d  d l j Z d d l m Z d d	 l m Z m Z d d
 l m Z d d l m Z m Z m Z d d d d d g Z d e  f d     YZ! e" d e d  d e d  d e d  d e d  d e d  d e d  d e d   d! e d"   Z# d e! f d#     YZ$ d e! f d$     YZ% d e  f d%     YZ& e' e' e' e' e' e' d& d' e' d( d e( e' e' e' e' d)  Z) e' d& e' e' d* d+ d, e( e' e' e' e' e' d-  Z* d S(.   i(   t   division(   t   product(   t   LooseVersionN(   t   dedent(   t   statsi   (   t   utils(   t   color_palettet   blend_palette(   t   string_types(   t   distplott   kdeplott   _freedman_diaconis_binst	   FacetGridt   PairGridt	   JointGridt   pairplott	   jointplott   Gridc           B   sY   e  Z d  Z e Z e Z d   Z d   Z d d d d  Z
 d   Z d   Z d   Z RS(   s!   Base class for grids of subplots.c         K   s(   x! |  j  j D] } | j |   q W|  S(   s$   Set attributes on each subplot Axes.(   t   axest   flatt   set(   t   selft   kwargst   ax(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR      s    c         O   s3   | j    } | j d d  |  j j | |   d S(   s   Save the figure.t   bbox_inchest   tightN(   t   copyt
   setdefaultt   figt   savefig(   R   t   argsR   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   !   s    c         K   s  | d k r |  j n | } | d k ri |  j d k rK t | j    } qi t t t j |  j   } n  t j	 j
 d d d d  } g  | D] } | j | |  ^ q } | d k r |  j n | } y t j d d } Wn t k
 r t j d } n X| j d d  |  j rz| j d t  |  j j | | d	 |  }	 |	 |  _ |	 j | d
 i | d 6t |  j j d  r|  j j |  j j j    n  |	 j   j |  j j }
 |  j j   \ } } |  j j | |
 |  t |  j j d  r|  j j |  j j j    n  |	 j   j |  j j }
 |
 | |
 } |  j rDd n d } | | |  _  d |  j  } |  j j! d |  nE |  j" j# d } | j | | d d | } | j | d
 i | d 6|  S(   s:  Draw a legend, maybe placing it outside axes and resizing the figure.

        Parameters
        ----------
        legend_data : dict, optional
            Dictionary mapping label names to matplotlib artist handles. The
            default reads from ``self._legend_data``.
        title : string, optional
            Title for the legend. The default reads from ``self._hue_var``.
        label_order : list of labels, optional
            The order that the legend entries should appear in. The default
            reads from ``self.hue_names``.
        kwargs : key, value pairings
            Other keyword arguments are passed to the underlying legend methods
            on the Figure or Axes object.

        Returns
        -------
        self : Grid instance
            Returns self for easy chaining.

        t   alphai    t	   linewidths   axes.labelsizeg333333?t   scatterpointsi   t   frameons   center rightt   propt   sizet   get_rendererg{Gz?g{Gz?t   rightt   loct   bestN($   t   Nonet   _legend_datat	   hue_namest   listt   keyst   mapR   t   to_utf8t   mplt   patchest   Patcht   gett   _hue_vart   rcParamst	   TypeErrorR   t   _legend_outt   FalseR   t   legendt   _legendt	   set_titlet   hasattrt   canvast   drawR%   t   get_window_extentt   widtht   dpit   get_size_inchest   set_size_inchest   _margin_titlest   _space_neededt   subplots_adjustR   R   (   R   t   legend_datat   titlet   label_orderR   t   blank_handlet   lt   handlest
   title_sizet	   figlegendt   legend_widtht	   fig_widtht
   fig_heightt   space_neededt   marginR&   R   t   leg(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt
   add_legend'   sH    %			c         C   s'   | j  d  | j d  d | _ |  S(   s    Turn off axis labels and legend.t    N(   t
   set_xlabelt
   set_ylabelR)   t   legend_(   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt   _clean_axis{   s    	c         C   s?   | j    \ } } d   t | |  D } |  j j |  d S(   s8   Extract the legend data from an axes object and save it.c         S   s   i  |  ] \ } } | |  q S(    (    (   t   .0t   hRK   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pys
   <dictcomp>   s   	 N(   t   get_legend_handles_labelst   zipR*   t   update(   R   R   RL   t   labelst   data(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt   _update_legend_data   s    c         C   s   | d k r t d d  } n t j | | |  } t |  } | d k r t j   } | t |  k r| t d |  } q t d |  } nM t | t  r g  | D] }	 | |	 ^ q }
 t |
 |  } n t | |  } t | |  } | S(   s*   Get a list of colors for the hue variable.t   n_colorsi   t   huslN(   R)   R   R   t   categorical_ordert   lent   get_color_cyclet
   isinstancet   dict(   R   Ra   t   huet	   hue_ordert   paletteR+   Rc   t   current_palettet   colorsR\   t   color_names(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt   _get_palette   s    N(   t   __name__t
   __module__t   __doc__R8   RD   t   TrueR7   R   R   R)   RU   RZ   Rb   Rp   (    (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR      s   		T		Ra   s       data : DataFrame
        Tidy ("long-form") dataframe where each column is a variable and each
        row is an observation.    t   col_wraps       col_wrap : int, optional
        "Wrap" the column variable at this width, so that the column facets
        span multiple rows. Incompatible with a ``row`` facet.    t   share_xys       share{x,y} : bool, 'col', or 'row' optional
        If true, the facets will share y axes across columns and/or x axes
        across rows.    t   heightsa       height : scalar, optional
        Height (in inches) of each facet. See also: ``aspect``.    t   aspects       aspect : scalar, optional
        Aspect ratio of each facet, so that ``aspect * height`` gives the width
        of each facet in inches.    Rl   s      palette : palette name, list, or dict, optional
        Colors to use for the different levels of the ``hue`` variable. Should
        be something that can be interpreted by :func:`color_palette`, or a
        dictionary mapping hue levels to matplotlib colors.    t
   legend_outs       legend_out : bool, optional
        If ``True``, the figure size will be extended, and the legend will be
        drawn outside the plot on the center right.    t   margin_titless       margin_titles : bool, optional
        If ``True``, the titles for the row variable are drawn to the right of
        the last column. This option is experimental and may not work in all
        cases.    c           B   sg  e  Z d  Z e e e e e e d d e e e e e e e e e e e e e e d  Z e d  j e	   e _ d   Z
 d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z e e d  Z e d  Z e d  Z e e d  Z e d  Z e e e d  Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z RS(   s7   Multi-plot grid for plotting conditional relationships.i   i   c   0      C   s  t  d  } t  t j  | k  } | d  k	 rL | } d } t j | t  n  | } | d  k rg d  } n t j | | |  } |  j	 | | | |
  } | d  k r g  } n t j | | |  } | d  k r g  } n t j | | |  } | d  k	 r | n i  } t
 j t |  t
 j  }  | r| d  k r6|  n | | j   }! | d  k rX|  n | | j   }" | d  k rz|  n | | j   }# |! |" B|# B}$ n |  }$ | d  k rd n	 t |  }% | d  k rd n	 t |  }& |% |& |  _ | |  _ | d  k	 rJ| d  k	 r"d }' t |'   n  | }% t t
 j t |  |   }& n  |% |  _ |& |  _ |% | |	 |& | f }( | d  k	 rt } n  | d  k ri  n	 | j   } | d  k ri  n	 | j   } | d  k	 r| | d <n  | d  k	 r| | d <n  | d  k rt d |( d t d	 | d
 | d | d |  }) | rn|) j d d   | rnd } t j | j |   qnn  t j |& |% |)  \ }* }+ |+ |  _ n{| rt j d  n  t |  }, t j d |(  }* t
 j |, t   }+ |* j! |& |% d |  |+ d <| r|+ d | d	 <n  | r%|+ d | d
 <n  x7 t" d |,  D]& }- |* j! |& |% |- d |  |+ |- <q5W|+ |  _ | rxK |  j# D]= }. x! |. j$   D] }/ |/ j% t  qW|. j& j' j% t  qxWn  | rxK |  j( D]= }. x! |. j)   D] }/ |/ j% t  qW|. j* j' j% t  qWn  | |  _+ |* |  _, |+ |  _ | |  _- | |  _. | |  _/ | |  _0 |& |  _ | |  _1 |% |  _ | |  _2 | |  _3 | |  _ | |  _4 | |  _5 | |  _6 d  |  _7 i  |  _8 d  |  _9 d  |  _: | |  _; |$ |  _< |* j=   | r|  j>   n  d  S(   Ns   1.4sJ   The `size` paramter has been renamed to `height`; please update your code.i   s)   Cannot use `row` and `col_wrap` together.t   xlimt   ylimt   figsizet   squeezet   sharext   shareyt
   subplot_kwt   gridspec_kws+   gridspec module only available in mpl >= {}s,   `gridspec_kws` ignored when using `col_wrap`i    (?   R   R0   t   __version__R)   t   warningst   warnt   UserWarningR   Re   Rp   t   npt   zerosRf   t   boolt   isnullt	   _n_facetst	   _col_wrapt
   ValueErrort   intt   ceilt   _ncolt   _nrowR8   R   Ri   t   popt   formatt   pltt   subplotsR   t   figuret   emptyt   objectt   add_subplott   ranget   _not_bottom_axest   get_xticklabelst   set_visiblet   xaxist
   offsetTextt   _not_left_axest   get_yticklabelst   yaxisRa   R   t	   row_namest	   col_namesR+   t   hue_kwst   _row_vart   _col_varRD   R4   t   _colorsR7   R:   R*   t   _x_vart   _y_vart   _dropnat   _not_nat   tight_layoutt   despine(0   R   Ra   t   rowt   colRj   Ru   R   R   Rw   Rx   Rl   t	   row_ordert	   col_orderRk   R   t   dropnaRy   R   Rz   R{   R|   t   subplot_kwst   gridspec_kwsR$   t   MPL_GRIDSPEC_VERSIONt   OLD_MPLt   msgt   hue_varR+   Rn   R   R   t   none_nat   row_nat   col_nat   hue_nat   not_nat   ncolt   nrowt   errR}   R   R   R   t   n_axest   iR   t   label(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt   __init__   s    			"""	"				$																							
s'          Initialize the matplotlib figure and FacetGrid object.

        This class maps a dataset onto multiple axes arrayed in a grid of rows
        and columns that correspond to *levels* of variables in the dataset.
        The plots it produces are often called "lattice", "trellis", or
        "small-multiple" graphics.

        It can also represent levels of a third varaible with the ``hue``
        parameter, which plots different subets of data in different colors.
        This uses color to resolve elements on a third dimension, but only
        draws subsets on top of each other and will not tailor the ``hue``
        parameter for the specific visualization the way that axes-level
        functions that accept ``hue`` will.

        When using seaborn functions that infer semantic mappings from a
        dataset, care must be taken to synchronize those mappings across
        facets. In most cases, it will be better to use a figure-level function
        (e.g. :func:`relplot` or :func:`catplot`) than to use
        :class:`FacetGrid` directly.

        The basic workflow is to initialize the :class:`FacetGrid` object with
        the dataset and the variables that are used to structure the grid. Then
        one or more plotting functions can be applied to each subset by calling
        :meth:`FacetGrid.map` or :meth:`FacetGrid.map_dataframe`. Finally, the
        plot can be tweaked with other methods to do things like change the
        axis labels, use different ticks, or add a legend. See the detailed
        code examples below for more information.

        See the :ref:`tutorial <grid_tutorial>` for more information.

        Parameters
        ----------
        {data}
        row, col, hue : strings
            Variables that define subsets of the data, which will be drawn on
            separate facets in the grid. See the ``*_order`` parameters to
            control the order of levels of this variable.
        {col_wrap}
        {share_xy}
        {height}
        {aspect}
        {palette}
        {{row,col,hue}}_order : lists, optional
            Order for the levels of the faceting variables. By default, this
            will be the order that the levels appear in ``data`` or, if the
            variables are pandas categoricals, the category order.
        hue_kws : dictionary of param -> list of values mapping
            Other keyword arguments to insert into the plotting call to let
            other plot attributes vary across levels of the hue variable (e.g.
            the markers in a scatterplot).
        {legend_out}
        despine : boolean, optional
            Remove the top and right spines from the plots.
        {margin_titles}
        {{x, y}}lim: tuples, optional
            Limits for each of the axes on each facet (only relevant when
            share{{x, y}} is True.
        subplot_kws : dict, optional
            Dictionary of keyword arguments passed to matplotlib subplot(s)
            methods.
        gridspec_kws : dict, optional
            Dictionary of keyword arguments passed to matplotlib's ``gridspec``
            module (via ``plt.subplots``). Requires matplotlib >= 1.4 and is
            ignored if ``col_wrap`` is not ``None``.

        See Also
        --------
        PairGrid : Subplot grid for plotting pairwise relationships.
        relplot : Combine a relational plot and a :class:`FacetGrid`.
        catplot : Combine a categorical plot and a :class:`FacetGrid`.
        lmplot : Combine a regression plot and a :class:`FacetGrid`.

        Examples
        --------

        Initialize a 2x2 grid of facets using the tips dataset:

        .. plot::
            :context: close-figs

            >>> import seaborn as sns; sns.set(style="ticks", color_codes=True)
            >>> tips = sns.load_dataset("tips")
            >>> g = sns.FacetGrid(tips, col="time", row="smoker")

        Draw a univariate plot on each facet:

        .. plot::
            :context: close-figs

            >>> import matplotlib.pyplot as plt
            >>> g = sns.FacetGrid(tips, col="time",  row="smoker")
            >>> g = g.map(plt.hist, "total_bill")

        (Note that it's not necessary to re-catch the returned variable; it's
        the same object, but doing so in the examples makes dealing with the
        doctests somewhat less annoying).

        Pass additional keyword arguments to the mapped function:

        .. plot::
            :context: close-figs

            >>> import numpy as np
            >>> bins = np.arange(0, 65, 5)
            >>> g = sns.FacetGrid(tips, col="time",  row="smoker")
            >>> g = g.map(plt.hist, "total_bill", bins=bins, color="r")

        Plot a bivariate function on each facet:

        .. plot::
            :context: close-figs

            >>> g = sns.FacetGrid(tips, col="time",  row="smoker")
            >>> g = g.map(plt.scatter, "total_bill", "tip", edgecolor="w")

        Assign one of the variables to the color of the plot elements:

        .. plot::
            :context: close-figs

            >>> g = sns.FacetGrid(tips, col="time",  hue="smoker")
            >>> g = (g.map(plt.scatter, "total_bill", "tip", edgecolor="w")
            ...       .add_legend())

        Change the height and aspect ratio of each facet:

        .. plot::
            :context: close-figs

            >>> g = sns.FacetGrid(tips, col="day", height=4, aspect=.5)
            >>> g = g.map(plt.hist, "total_bill", bins=bins)

        Specify the order for plot elements:

        .. plot::
            :context: close-figs

            >>> g = sns.FacetGrid(tips, col="smoker", col_order=["Yes", "No"])
            >>> g = g.map(plt.hist, "total_bill", bins=bins, color="m")

        Use a different color palette:

        .. plot::
            :context: close-figs

            >>> kws = dict(s=50, linewidth=.5, edgecolor="w")
            >>> g = sns.FacetGrid(tips, col="sex", hue="time", palette="Set1",
            ...                   hue_order=["Dinner", "Lunch"])
            >>> g = (g.map(plt.scatter, "total_bill", "tip", **kws)
            ...      .add_legend())

        Use a dictionary mapping hue levels to colors:

        .. plot::
            :context: close-figs

            >>> pal = dict(Lunch="seagreen", Dinner="gray")
            >>> g = sns.FacetGrid(tips, col="sex", hue="time", palette=pal,
            ...                   hue_order=["Dinner", "Lunch"])
            >>> g = (g.map(plt.scatter, "total_bill", "tip", **kws)
            ...      .add_legend())

        Additionally use a different marker for the hue levels:

        .. plot::
            :context: close-figs

            >>> g = sns.FacetGrid(tips, col="sex", hue="time", palette=pal,
            ...                   hue_order=["Dinner", "Lunch"],
            ...                   hue_kws=dict(marker=["^", "v"]))
            >>> g = (g.map(plt.scatter, "total_bill", "tip", **kws)
            ...      .add_legend())

        "Wrap" a column variable with many levels into the rows:

        .. plot::
            :context: close-figs

            >>> att = sns.load_dataset("attention")
            >>> g = sns.FacetGrid(att, col="subject", col_wrap=5, height=1.5)
            >>> g = g.map(plt.plot, "solutions", "score", marker=".")

        Define a custom bivariate function to map onto the grid:

        .. plot::
            :context: close-figs

            >>> from scipy import stats
            >>> def qqplot(x, y, **kwargs):
            ...     _, xr = stats.probplot(x, fit=False)
            ...     _, yr = stats.probplot(y, fit=False)
            ...     plt.scatter(xr, yr, **kwargs)
            >>> g = sns.FacetGrid(tips, col="smoker", hue="sex")
            >>> g = (g.map(qqplot, "total_bill", "tip", **kws)
            ...       .add_legend())

        Define a custom function that uses a ``DataFrame`` object and accepts
        column names as positional variables:

        .. plot::
            :context: close-figs

            >>> import pandas as pd
            >>> df = pd.DataFrame(
            ...     data=np.random.randn(90, 4),
            ...     columns=pd.Series(list("ABCD"), name="walk"),
            ...     index=pd.date_range("2015-01-01", "2015-03-31",
            ...                         name="date"))
            >>> df = df.cumsum(axis=0).stack().reset_index(name="val")
            >>> def dateplot(x, y, **kwargs):
            ...     ax = plt.gca()
            ...     data = kwargs.pop("data")
            ...     data.plot(x=x, y=y, ax=ax, grid=False, **kwargs)
            >>> g = sns.FacetGrid(df, col="walk", col_wrap=2, height=3.5)
            >>> g = g.map_dataframe(dateplot, "date", "val")

        Use different axes labels after plotting:

        .. plot::
            :context: close-figs

            >>> g = sns.FacetGrid(tips, col="smoker", row="sex")
            >>> g = (g.map(plt.scatter, "total_bill", "tip", color="g", **kws)
            ...       .set_axis_labels("Total bill (US Dollars)", "Tip"))

        Set other attributes that are shared across the facetes:

        .. plot::
            :context: close-figs

            >>> g = sns.FacetGrid(tips, col="smoker", row="sex")
            >>> g = (g.map(plt.scatter, "total_bill", "tip", color="r", **kws)
            ...       .set(xlim=(0, 60), ylim=(0, 12),
            ...            xticks=[10, 30, 50], yticks=[2, 6, 10]))

        Use a different template for the facet titles:

        .. plot::
            :context: close-figs

            >>> g = sns.FacetGrid(tips, col="size", col_wrap=3)
            >>> g = (g.map(plt.hist, "tip", bins=np.arange(0, 13), color="c")
            ...       .set_titles("{{col_name}} diners"))

        Tighten the facets:

        .. plot::
            :context: close-figs

            >>> g = sns.FacetGrid(tips, col="smoker", row="sex",
            ...                   margin_titles=True)
            >>> g = (g.map(plt.scatter, "total_bill", "tip", color="m", **kws)
            ...       .set(xlim=(0, 60), ylim=(0, 12),
            ...            xticks=[10, 30, 50], yticks=[2, 6, 10])
            ...       .fig.subplots_adjust(wspace=.05, hspace=.05))

        c         c   s}  |  j  } |  j r> g  |  j D] } | |  j | k ^ q } n t j t t |  j    g } |  j r g  |  j D] } | |  j | k ^ qo } n t j t t |  j    g } |  j	 r g  |  j	 D] } | |  j
 | k ^ q } n t j t t |  j    g } xt t t |  t |  t |   D]N \ \ } } \ } }	 \ }
 } | | |	 @| @|  j @} | | |
 f | f Vq'Wd S(   s  Generator for name indices and data subsets for each facet.

        Yields
        ------
        (i, j, k), data_ijk : tuple of ints, DataFrame
            The ints provide an index into the {row, col, hue}_names attribute,
            and the dataframe contains a subset of the full data corresponding
            to each facet. The generator yields subsets that correspond with
            the self.axes.flat iterator, or self.axes[i, j] when `col_wrap`
            is None.

        N(   Ra   R   R   R   t   repeatRt   Rf   R   R   R+   R4   R   t	   enumerateR   (   R   Ra   t   nt	   row_maskst	   col_maskst	   hue_masksR   R   t   jR   t   kRj   t   data_ijk(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt
   facet_data~  s    		,	,	,	.c         O   s  | j  d d  } t | d  r3 t | j  } n d } | d k r d | k rs d j | j  } t j |  n  t	 |  d k r d | k r d	 j | j  } t j |  q n  xH|  j
   D]:\ \ } } }	 }
 |
 j j s q n  |  j | |  } |  j |	 |  | d <x+ |  j j   D] \ } } | |	 | | <q"W|  j d k	 rlt j |  j |	  | d
 <n  |
 t |  } |  j r| j   } n  g  | j   D] \ } } | ^ q} | j d  rg  | D] } | j ^ q} n  |  j | | | |  q W|  j | d   |  S(   s=  Apply a plotting function to each facet's subset of the data.

        Parameters
        ----------
        func : callable
            A plotting function that takes data and keyword arguments. It
            must plot to the currently active matplotlib Axes and take a
            `color` keyword argument. If faceting on the `hue` dimension,
            it must also take a `label` keyword argument.
        args : strings
            Column names in self.data that identify variables with data to
            plot. The data for each variable is passed to `func` in the
            order the variables are specified in the call.
        kwargs : keyword arguments
            All keyword arguments are passed to the plotting function.

        Returns
        -------
        self : object
            Returns self.

        t   colorRr   RV   s   seaborn.categoricalt   ordersX   Using the {} function without specifying `order` is likely to produce an incorrect plot.i   Rk   s\   Using the {} function without specifying `hue_order` is likely to produce an incorrect plot.R   t
   matplotlibi   N(   R   R)   R<   t   strRr   R   Rq   R   R   Rf   R   t   valuesR$   t
   facet_axist   _facet_colorR   t   itemsR4   R   R/   R+   R,   R   R   t	   iteritemst
   startswitht   _facet_plott   _finalize_grid(   R   t   funcR   R   t   kw_colort   func_modulet   warningt   row_it   col_jt   hue_kR   R   t   kwt   val_listt	   plot_dataR   t   vt	   plot_args(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR.     s>    "	%c         O   s  | j  d d  } x |  j   D] \ \ } } } } | j j sF q n  |  j | |  }	 |  j | |  | d <x+ |  j j   D] \ }
 } | | | |
 <q~ W|  j	 d k	 r |  j
 | | d <n  |  j r | j   } n  | | d <|  j | |	 | |  q W|  j | d   |  S(   st  Like ``.map`` but passes args as strings and inserts data in kwargs.

        This method is suitable for plotting with functions that accept a
        long-form DataFrame as a `data` keyword argument and access the
        data in that DataFrame using string variable names.

        Parameters
        ----------
        func : callable
            A plotting function that takes data and keyword arguments. Unlike
            the `map` method, a function used here must "understand" Pandas
            objects. It also must plot to the currently active matplotlib Axes
            and take a `color` keyword argument. If faceting on the `hue`
            dimension, it must also take a `label` keyword argument.
        args : strings
            Column names in self.data that identify variables with data to
            plot. The data for each variable is passed to `func` in the
            order the variables are specified in the call.
        kwargs : keyword arguments
            All keyword arguments are passed to the plotting function.

        Returns
        -------
        self : object
            Returns self.

        R   R   Ra   i   N(   R   R)   R   R   R$   R   R   R   R   R4   R+   R   R   R   R   (   R   R   R   R   R   R   R   R   R   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt   map_dataframe  s     "	
c         C   s1   |  j  | } | d  k	 r | S| d  k	 r- | Sd  S(   N(   R   R)   (   R   t	   hue_indexR   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   ;  s
    c         C   s+   | | |   |  j  |  |  j |  d  S(   N(   Rb   RZ   (   R   R   R   R   t   plot_kwargs(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   C  s    c         C   s(   |  j  |   |  j   |  j j   d S(   s$   Finalize the annotations and layout.N(   t   set_axis_labelst
   set_titlesR   R   (   R   t   axlabels(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   L  s    
c         C   sF   |  j  d k	 r" |  j j | } n |  j | | f } t j |  | S(   s?   Make the axis identified by these indices active and return it.N(   R   R)   R   R   R   t   sca(   R   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   R  s
    c         K   s   t  j |  j |  |  S(   s#   Remove axis spines from the facets.(   R   R   R   (   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   _  s    c         C   sN   | d k	 r% | |  _ |  j |  n  | d k	 rJ | |  _ |  j |  n  |  S(   s>   Set axis labels on the left column and bottom row of the grid.N(   R)   R   t   set_xlabelsR   t   set_ylabels(   R   t   x_vart   y_var(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   d  s    		c         K   s@   | d k r |  j } n  x! |  j D] } | j | |  q" W|  S(   s/   Label the x axis on the bottom row of the grid.N(   R)   R   t   _bottom_axesRW   (   R   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   n  s
    c         K   s@   | d k r |  j } n  x! |  j D] } | j | |  q" W|  S(   s0   Label the y axis on the left column of the grid.N(   R)   R   t
   _left_axesRX   (   R   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   v  s
    c         K   s   x |  j  j D] } | d k r g  | j   D] } | j   ^ q, } | d k	 r | j   d d |  } | d d |  } | j |  q n  | j | |  q W|  S(   s5   Set x axis tick labels on the bottom row of the grid.N(   R   R   R)   R   t   get_textt
   get_xtickst
   set_xtickst   set_xticklabels(   R   R`   t   stepR   R   RK   t   xticks(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   ~  s    %c         K   s_   xX |  j  j D]J } | d k rG g  | j   D] } | j   ^ q, } n  | j | |  q W|  S(   s6   Set y axis tick labels on the left column of the grid.N(   R   R   R)   R   R   t   set_yticklabels(   R   R`   R   R   RK   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR     s
    (c         K   s  t  d |  j d |  j  } | j d t j d  | d <| d k rM d } n  | d k rb d } n  | d k r |  j d k r | } q |  j d k r | } q d j | | g  } n  t j	 |  } t j	 |  } t j	 |  } |  j
 r|  j d k	 rx t |  j  D] \ } } |  j | d f } | j t  d	 |   | j |   }	 |  j j   }
 | j |	 d
 d d d d d d d d d d |
 | qWn  |  j d k	 rxb t |  j  D]N \ } } | j t  d |   | j |   }	 |  j d | f j |	 |  qWn  |  S|  j d k	 r|  j d k	 rxt |  j  D]t \ } } xe t |  j  D]T \ } } | j t  d	 | d |   | j |   }	 |  j | | f j |	 |  q[Wq?Wn|  j d k	 r=t |  j  r=x t |  j  D]N \ } } | j t  d	 |   | j |   }	 |  j | d f j |	 |  qWn |  j d k	 rt |  j  rx_ t |  j  D]K \ } } | j t  d |   | j |   }	 |  j j | j |	 |  qkWn  |  S(   s  Draw titles either above each facet or on the grid margins.

        Parameters
        ----------
        template : string
            Template for all titles with the formatting keys {col_var} and
            {col_name} (if using a `col` faceting variable) and/or {row_var}
            and {row_name} (if using a `row` faceting variable).
        row_template:
            Template for the row variable when titles are drawn on the grid
            margins. Must have {row_var} and {row_name} formatting keys.
        col_template:
            Template for the row variable when titles are drawn on the grid
            margins. Must have {col_var} and {col_name} formatting keys.

        Returns
        -------
        self: object
            Returns self.

        t   row_vart   col_varR$   s   axes.labelsizes   {row_var} = {row_name}s   {col_var} = {col_name}s    | it   row_namet   xygRQ?g      ?t   xycoordss   axes fractiont   rotationi  t   hat   leftt   vat   centert   backgroundcolort   col_namei    N(   gRQ?g      ?(   Ri   R   R   R   R0   R5   R)   t   joinR   R/   RD   R   R   R   R_   R   R   t   get_facecolort   annotateR   R;   Rf   R   (   R   t   templatet   row_templatet   col_templateR   R   R   R   R   RH   t   bgcolorR   R  (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR     s`    					$($!c         C   s3   |  j  j d k r |  j  d Sd } t |   d S(   s   Easy access to single axes.i   i    sO   You must use the `.axes` attribute (an array) when there is more than one plot.N(   i   i   (   i    i    (   R   t   shapet   AttributeError(   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR     s    c         C   s   |  j  d k r/ |  j d d  d d  f j Sg  } |  j |  j |  j } xx t |  j  D]g \ } } | |  j o | |  j |  j d k  o | |  j |  j d | k  } | r\ | j |  q\ q\ Wt	 j
 | t  j Sd S(   s&   Return a flat array of the inner axes.Nii   (   R   R)   R   R   R   R   R   R   t   appendR   t   arrayR   (   R   R   t   n_emptyR   R   R  (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt   _inner_axes  s     c         C   s   |  j  d k r) |  j d d  d f j Sg  } x: t |  j  D]) \ } } | |  j s? | j |  q? q? Wt j | t	  j Sd S(   s/   Return a flat array of the left column of axes.Ni    (
   R   R)   R   R   R   R   R  R   R  R   (   R   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR      s    c         C   s   |  j  d k r/ |  j d d  d d  f j Sg  } x: t |  j  D]) \ } } | |  j rE | j |  qE qE Wt j | t	  j Sd S(   s;   Return a flat array of axes that aren't on the left column.Ni   (
   R   R)   R   R   R   R   R  R   R  R   (   R   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR     s     c         C   s   |  j  d k r) |  j d d d  f j Sg  } |  j |  j |  j } xk t |  j  D]Z \ } } | |  j |  j d k p | |  j |  j d | k } | rV | j |  qV qV Wt	 j
 | t  j Sd S(   s.   Return a flat array of the bottom row of axes.iNi   (   R   R)   R   R   R   R   R   R   R  R   R  R   (   R   R   R  R   R   R  (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR     s    c         C   s   |  j  d k r/ |  j d d  d d  f j Sg  } |  j |  j |  j } xk t |  j  D]Z \ } } | |  j |  j d k  o | |  j |  j d | k  } | r\ | j |  q\ q\ Wt	 j
 | t  j Sd S(   s:   Return a flat array of axes that aren't on the bottom row.Nii   (   R   R)   R   R   R   R   R   R   R  R   R  R   (   R   R   R  R   R   R  (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   '  s     (   Rq   Rr   Rs   R)   Rt   R8   R   R   R   t   _facet_docsR   R.   R   R   R   R   R   R   R   R   R   R   R   R   t   propertyR   R  R   R   R   R   (    (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR      s<   	 	(	S	B						
T
c           B   s}   e  Z d  Z d d d d d d d e d d e e d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z RS(   sN  Subplot grid for plotting pairwise relationships in a dataset.

    This class maps each variable in a dataset onto a column and row in a
    grid of multiple axes. Different axes-level plotting functions can be
    used to draw bivariate plots in the upper and lower triangles, and the
    the marginal distribution of each variable can be shown on the diagonal.

    It can also represent an additional level of conditionalization with the
    ``hue`` parameter, which plots different subets of data in different
    colors. This uses color to resolve elements on a third dimension, but
    only draws subsets on top of each other and will not tailor the ``hue``
    parameter for the specific visualization the way that axes-level functions
    that accept ``hue`` will.

    See the :ref:`tutorial <grid_tutorial>` for more information.

    g      @i   c         C   s  | d k	 r. | }
 d } t j t |   n  | d k	 rU t |  } t |  } n] | d k	 sm | d k	 r | d k s | d k r t d   q n |  j |  } | } | } t j |  r | g } n  t j |  r | g } n  t |  |  _	 t |  |  _
 |  j	 |  j
 k |  _ t |  |
 | t |  |
 f } t j t |  t |  d | d d d d d t \ } } | |  _ | |  _ | |  _ |	 |  _ d |  _ |  j   | |  _ | d k rd	 g |  _ t j d	 g t |  d
 | j |  _ nM t j | | |  } | r5t t t j |   } n  | |  _ | | |  _ | d k	 r]| n i  |  _  |  j! | | | |  |  _" i  |  _# | rt j$ d |  n  | j%   d S(   sh  Initialize the plot figure and PairGrid object.

        Parameters
        ----------
        data : DataFrame
            Tidy (long-form) dataframe where each column is a variable and
            each row is an observation.
        hue : string (variable name), optional
            Variable in ``data`` to map plot aspects to different colors.
        hue_order : list of strings
            Order for the levels of the hue variable in the palette
        palette : dict or seaborn color palette
            Set of colors for mapping the ``hue`` variable. If a dict, keys
            should be values  in the ``hue`` variable.
        hue_kws : dictionary of param -> list of values mapping
            Other keyword arguments to insert into the plotting call to let
            other plot attributes vary across levels of the hue variable (e.g.
            the markers in a scatterplot).
        vars : list of variable names, optional
            Variables within ``data`` to use, otherwise use every column with
            a numeric datatype.
        {x, y}_vars : lists of variable names, optional
            Variables within ``data`` to use separately for the rows and
            columns of the figure; i.e. to make a non-square plot.
        height : scalar, optional
            Height (in inches) of each facet.
        aspect : scalar, optional
            Aspect * height gives the width (in inches) of each facet.
        despine : boolean, optional
            Remove the top and right spines from the plots.
        dropna : boolean, optional
            Drop missing values from the data before plotting.

        See Also
        --------
        pairplot : Easily drawing common uses of :class:`PairGrid`.
        FacetGrid : Subplot grid for plotting conditional relationships.

        Examples
        --------

        Draw a scatterplot for each pairwise relationship:

        .. plot::
            :context: close-figs

            >>> import matplotlib.pyplot as plt
            >>> import seaborn as sns; sns.set()
            >>> iris = sns.load_dataset("iris")
            >>> g = sns.PairGrid(iris)
            >>> g = g.map(plt.scatter)

        Show a univariate distribution on the diagonal:

        .. plot::
            :context: close-figs

            >>> g = sns.PairGrid(iris)
            >>> g = g.map_diag(plt.hist)
            >>> g = g.map_offdiag(plt.scatter)

        (It's not actually necessary to catch the return value every time,
        as it is the same object, but it makes it easier to deal with the
        doctests).

        Color the points using a categorical variable:

        .. plot::
            :context: close-figs

            >>> g = sns.PairGrid(iris, hue="species")
            >>> g = g.map_diag(plt.hist)
            >>> g = g.map_offdiag(plt.scatter)
            >>> g = g.add_legend()

        Use a different style to show multiple histograms:

        .. plot::
            :context: close-figs

            >>> g = sns.PairGrid(iris, hue="species")
            >>> g = g.map_diag(plt.hist, histtype="step", linewidth=3)
            >>> g = g.map_offdiag(plt.scatter)
            >>> g = g.add_legend()

        Plot a subset of variables

        .. plot::
            :context: close-figs

            >>> g = sns.PairGrid(iris, vars=["sepal_length", "sepal_width"])
            >>> g = g.map(plt.scatter)

        Pass additional keyword arguments to the functions

        .. plot::
            :context: close-figs

            >>> g = sns.PairGrid(iris)
            >>> g = g.map_diag(plt.hist, edgecolor="w")
            >>> g = g.map_offdiag(plt.scatter, edgecolor="w", s=40)

        Use different variables for the rows and columns:

        .. plot::
            :context: close-figs

            >>> g = sns.PairGrid(iris,
            ...                  x_vars=["sepal_length", "sepal_width"],
            ...                  y_vars=["petal_length", "petal_width"])
            >>> g = g.map(plt.scatter)

        Use different functions on the upper and lower triangles:

        .. plot::
            :context: close-figs

            >>> g = sns.PairGrid(iris)
            >>> g = g.map_upper(plt.scatter)
            >>> g = g.map_lower(sns.kdeplot, cmap="Blues_d")
            >>> g = g.map_diag(sns.kdeplot, lw=3, legend=False)

        Use different colors and markers for each categorical level:

        .. plot::
            :context: close-figs

            >>> g = sns.PairGrid(iris, hue="species", palette="Set2",
            ...                  hue_kws={"marker": ["o", "s", "D"]})
            >>> g = g.map(plt.scatter, linewidths=1, edgecolor="w", s=40)
            >>> g = g.add_legend()

        sJ   The `size` paramter has been renamed to `height`; please update your code.s"   Must specify `x_vars` and `y_vars`R}   R   R   R   R   R~   t
   _nolegend_t   indexR   N(&   R)   R   R   R   R,   R   t   _find_numeric_colsR   t   isscalart   x_varst   y_varst   square_gridRf   R   R   R8   R   R   Ra   t   diag_shareyt	   diag_axest   _add_axis_labelsR4   R+   t   pdt   SeriesR  t   hue_valsR   Re   t   filtert   notnullR   Rp   Rl   R*   R   R   (   R   Ra   Rj   Rk   Rl   R   t   varsR  R  R  Rw   Rx   R   R   R$   R   t   numeric_colsR}   R   R   R+   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   J  s^    $					
			c         K   s  | j  d d  } xet |  j  D]T\ } } xEt |  j  D]4\ } } |  j j |  j  } x t |  j  D] \ }	 }
 y | j	 |
  } Wn2 t
 k
 r t j d |  j j d t j  } n X|  j | | f } t j |  x+ |  j j   D] \ } } | |	 | | <q W| d k r*|  j |	 n | } | | | | | d |
 d | | qo W|  j |  |  j |  q> Wq" W| d k	 r| | d <n  |  j   |  S(   sM  Plot with the same function in every subplot.

        Parameters
        ----------
        func : callable plotting function
            Must take x, y arrays as positional arguments and draw onto the
            "currently active" matplotlib Axes. Also needs to accept kwargs
            called ``color`` and  ``label``.

        R   t   columnst   dtypeR   N(   R   R)   R   R  R  Ra   t   groupbyR#  R+   t	   get_groupt   KeyErrorR!  t	   DataFrameR(  R   t   floatR   R   R   R   R   Rl   RZ   Rb   R   (   R   R   R   R   R   R   R   R   t   hue_groupedR   t   label_kt   data_kR   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR.     s.    
c      	   K   s  |  j  r |  j d k r g  } x t t |  j t j |  j    D]u \ } \ } } | r |  j	 r | j
 d | d | d d t  } n | j
 d | d t  } | j   | j |  qC Wt j | t j  |  _ n  | j d d  } x t |  j  D] \ } } |  j | } |  j | j |  j  }	 t j |  x t |  j  D] \ }
 } y t j |	 j |   } Wn  t k
 rt j g   } n X| d k r|  j |
 } n | } | | d | d | | qHW|  j |  q W|  j   |  S(   sY  Plot with a univariate function on each diagonal subplot.

        Parameters
        ----------
        func : callable plotting function
            Must take an x array as a positional argument and draw onto the
            "currently active" matplotlib Axes. Also needs to accept kwargs
            called ``color`` and  ``label``.

        R   R   i    R"   R   R   N(   R  R  R)   R   R^   R  R   t   diagR   R  t   _make_twin_axesR8   t   set_axis_offR  R  R   R   Ra   R*  R#  R   R   R+   t   asarrayR+  R,  Rl   RZ   R   (   R   R   R   R  R   t   varR   t   diag_axt   fixed_colorR/  R   R0  R1  R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt   map_diagH  s:    (


c      
   K   s  | j  d d  } xkt t j |  j d    D]N\ } } |  j j |  j  } xt	 |  j
  D] \ } } y | j |  }	 Wn2 t k
 r t j d |  j j d t j  }	 n X|  j | | f }
 t j |
  |  j | } |  j | } x+ |  j j   D] \ } } | | | | <q W| d k r4|  j | n | } | |	 | |	 | d | d | | q_ W|  j |
  |  j |
  q. W| d k	 r| | d <n  |  j   |  S(   s^  Plot with a bivariate function on the lower diagonal subplots.

        Parameters
        ----------
        func : callable plotting function
            Must take x, y arrays as positional arguments and draw onto the
            "currently active" matplotlib Axes. Also needs to accept kwargs
            called ``color`` and  ``label``.

        R   iR(  R)  R   N(   R   R)   R^   R   t   tril_indices_fromR   Ra   R*  R#  R   R+   R+  R,  R!  R-  R(  R.  R   R   R  R  R   R   Rl   RZ   Rb   R   (   R   R   R   R   R   R   R/  R   R0  R1  R   R   R   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt	   map_lower  s0    (
c      
   K   s  | j  d d  } xkt t j |  j d    D]N\ } } |  j j |  j  } xt	 |  j
  D] \ } } y | j |  }	 Wn2 t k
 r t j d |  j j d t j  }	 n X|  j | | f }
 t j |
  |  j | } |  j | } x+ |  j j   D] \ } } | | | | <q W| d k r4|  j | n | } | |	 | |	 | d | d | | q_ W|  j |
  |  j |
  q. W| d k	 r| | d <n  |  S(   s^  Plot with a bivariate function on the upper diagonal subplots.

        Parameters
        ----------
        func : callable plotting function
            Must take x, y arrays as positional arguments and draw onto the
            "currently active" matplotlib Axes. Also needs to accept kwargs
            called ``color`` and  ``label``.

        R   i   R(  R)  R   N(   R   R)   R^   R   t   triu_indices_fromR   Ra   R*  R#  R   R+   R+  R,  R!  R-  R(  R.  R   R   R  R  R   R   Rl   RZ   Rb   (   R   R   R   R   R   R   R/  R   R0  R1  R   R   R   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt	   map_upper  s.    (c         K   s$   |  j  | |  |  j | |  |  S(   s\  Plot with a bivariate function on the off-diagonal subplots.

        Parameters
        ----------
        func : callable plotting function
            Must take x, y arrays as positional arguments and draw onto the
            "currently active" matplotlib Axes. Also needs to accept kwargs
            called ``color`` and  ``label``.

        (   R;  R=  (   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt   map_offdiag  s    c         C   s   x@ t  |  j d d d  f |  j  D] \ } } | j |  q& Wx@ t  |  j d d  d f |  j  D] \ } } | j |  qi Wd S(   s'   Add labels to the left and bottom Axes.iNi    (   R^   R   R  RW   R  RX   (   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR     s    22c         C   sZ   g  } xM | D]E } y% | | j  t j  | j |  Wq t t f k
 rQ q Xq W| S(   s0   Find which variables in a DataFrame are numeric.(   t   astypeR   R.  R  R   R6   (   R   Ra   R'  R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR    s    N(   Rq   Rr   Rs   R)   Rt   R   R.   R9  R;  R=  R>  R   R  (    (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   7  s   			,	7	.	/		c        	   B   sw   e  Z d  Z d d d d e d d d d  Z d d  Z d   Z d   Z d d d d	  Z	 d
 d
 d  Z
 d   Z RS(   sA   Grid for drawing a bivariate plot with marginal univariate plots.i   i   g?c         C   s  |
 d k	 r+ |
 } d } t j | t  n  t j d | | f  } t j | d | d  } | j | d d  d d  f  } | j | d d d  f d | } | j | d d  d f d | } | |  _ | |  _	 | |  _
 | |  _ t j | j   d	 t t j | j   d	 t t j | j j   d	 t t j | j j   d	 t t j | j j   d	 t t j | j j   d	 t t j | j   d	 t t j | j   d	 t | j j t  | j j t  | d k	 r| j | |  } | j | |  } n  xA | | g D]3 } t | t  r$d
 j |  } t |   q$q$Wt | d  r| j } | j |  n  t | d  r| j } | j |  n  t j |  } t j |  } | rt  j! |  t  j! |  @} | | } | | } n  | |  _" | |  _# | d k	 r0| j$ |  n  |	 d k	 rL| j% |	  n  t& j' |  t& j' d | d t(  t& j' d | d t(  | j)   | j* d | d |  d S(   s2  Set up the grid of subplots.

        Parameters
        ----------
        x, y : strings or vectors
            Data or names of variables in ``data``.
        data : DataFrame, optional
            DataFrame when ``x`` and ``y`` are variable names.
        height : numeric
            Size of each side of the figure in inches (it will be square).
        ratio : numeric
            Ratio of joint axes size to marginal axes height.
        space : numeric, optional
            Space between the joint and marginal axes
        dropna : bool, optional
            If True, remove observations that are missing from `x` and `y`.
        {x, y}lim : two-tuples, optional
            Axis limits to set before plotting.

        See Also
        --------
        jointplot : High-level interface for drawing bivariate plots with
                    several different default plot kinds.

        Examples
        --------

        Initialize the figure but don't draw any plots onto it:

        .. plot::
            :context: close-figs

            >>> import seaborn as sns; sns.set(style="ticks", color_codes=True)
            >>> tips = sns.load_dataset("tips")
            >>> g = sns.JointGrid(x="total_bill", y="tip", data=tips)

        Add plots using default parameters:

        .. plot::
            :context: close-figs

            >>> g = sns.JointGrid(x="total_bill", y="tip", data=tips)
            >>> g = g.plot(sns.regplot, sns.distplot)

        Draw the join and marginal plots separately, which allows finer-level
        control other parameters:

        .. plot::
            :context: close-figs

            >>> import matplotlib.pyplot as plt
            >>> g = sns.JointGrid(x="total_bill", y="tip", data=tips)
            >>> g = g.plot_joint(plt.scatter, color=".5", edgecolor="white")
            >>> g = g.plot_marginals(sns.distplot, kde=False, color=".5")

        Draw the two marginal plots separately:

        .. plot::
            :context: close-figs

            >>> import numpy as np
            >>> g = sns.JointGrid(x="total_bill", y="tip", data=tips)
            >>> g = g.plot_joint(plt.scatter, color="m", edgecolor="white")
            >>> _ = g.ax_marg_x.hist(tips["total_bill"], color="b", alpha=.6,
            ...                      bins=np.arange(0, 60, 5))
            >>> _ = g.ax_marg_y.hist(tips["tip"], color="r", alpha=.6,
            ...                      orientation="horizontal",
            ...                      bins=np.arange(0, 12, 1))

        Add an annotation with a statistic summarizing the bivariate
        relationship:

        .. plot::
            :context: close-figs

            >>> from scipy import stats
            >>> g = sns.JointGrid(x="total_bill", y="tip", data=tips)
            >>> g = g.plot_joint(plt.scatter,
            ...                  color="g", s=40, edgecolor="white")
            >>> g = g.plot_marginals(sns.distplot, kde=False, color="g")
            >>> g = g.annotate(stats.pearsonr)

        Use a custom function and formatting for the annotation

        .. plot::
            :context: close-figs

            >>> g = sns.JointGrid(x="total_bill", y="tip", data=tips)
            >>> g = g.plot_joint(plt.scatter,
            ...                  color="g", s=40, edgecolor="white")
            >>> g = g.plot_marginals(sns.distplot, kde=False, color="g")
            >>> rsquare = lambda a, b: stats.pearsonr(a, b)[0] ** 2
            >>> g = g.annotate(rsquare, template="{stat}: {val:.2f}",
            ...                stat="$R^2$", loc="upper left", fontsize=12)

        Remove the space between the joint and marginal axes:

        .. plot::
            :context: close-figs

            >>> g = sns.JointGrid(x="total_bill", y="tip", data=tips, space=0)
            >>> g = g.plot_joint(sns.kdeplot, cmap="Blues_d")
            >>> g = g.plot_marginals(sns.kdeplot, shade=True)

        Draw a smaller plot with relatively larger marginal axes:

        .. plot::
            :context: close-figs

            >>> g = sns.JointGrid(x="total_bill", y="tip", data=tips,
            ...                   height=5, ratio=2)
            >>> g = g.plot_joint(sns.kdeplot, cmap="Reds_d")
            >>> g = g.plot_marginals(sns.kdeplot, color="r", shade=True)

        Set limits on the axes:

        .. plot::
            :context: close-figs

            >>> g = sns.JointGrid(x="total_bill", y="tip", data=tips,
            ...                   xlim=(0, 50), ylim=(0, 8))
            >>> g = g.plot_joint(sns.kdeplot, cmap="Purples_d")
            >>> g = g.plot_marginals(sns.kdeplot, color="m", shade=True)

        sK   The `size` parameter has been renamed to `height`; pleaes update your code.R}   i   Nii    R   R   t   visibles   Could not interpret input '{}'t   nameR   R  t   bottomt   hspacet   wspace(+   R)   R   R   R   R   R   t   GridSpecR   R   t   ax_jointt	   ax_marg_xt	   ax_marg_yt   setpR   R8   R   R   t   get_majorticklinest   get_minorticklinesR   t   gridR3   Rh   R   R   R   R<   RA  RW   RX   R   R5  R!  R%  t   xt   yt   set_xlimt   set_ylimR   R   Rt   R   RF   (   R   RM  RN  Ra   Rw   t   ratiot   spaceR   R{   R|   R$   R   t   ft   gsRF  RG  RH  R6  R   t   xlabelt   ylabelt   x_arrayt   y_arrayR   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR     sj    %%%						
		
c         C   s:   |  j  |  |  j |  | d k	 r6 |  j |  n  |  S(   sh  Shortcut to draw the full plot.

        Use `plot_joint` and `plot_marginals` directly for more control.

        Parameters
        ----------
        joint_func, marginal_func: callables
            Functions to draw the bivariate and univariate plots.

        Returns
        -------
        self : JointGrid instance
            Returns `self`.

        N(   t   plot_marginalst
   plot_jointR)   R
  (   R   t
   joint_funct   marginal_funct
   annot_func(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt   plot  s
    c         K   s*   t  j |  j  | |  j |  j |  |  S(   s  Draw a bivariate plot of `x` and `y`.

        Parameters
        ----------
        func : plotting callable
            This must take two 1d arrays of data as the first two
            positional arguments, and it must plot on the "current" axes.
        kwargs : key, value mappings
            Keyword argument are passed to the plotting function.

        Returns
        -------
        self : JointGrid instance
            Returns `self`.

        (   R   R   RF  RM  RN  (   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyRZ    s    c         K   sX   t  | d <t j |  j  | |  j |  t | d <t j |  j  | |  j |  |  S(   sJ  Draw univariate plots for `x` and `y` separately.

        Parameters
        ----------
        func : plotting callable
            This must take a 1d array of data as the first positional
            argument, it must plot on the "current" axes, and it must
            accept a "vertical" keyword argument to orient the measure
            dimension of the plot vertically.
        kwargs : key, value mappings
            Keyword argument are passed to the plotting function.

        Returns
        -------
        self : JointGrid instance
            Returns `self`.

        t   vertical(   R8   R   R   RG  RM  Rt   RH  RN  (   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyRY    s    

R(   c         K   sF  d } t  j t |   d } | |  j |  j  } y | \ }	 }
 Wn3 t k
 ry | d }	 }
 | j d  \ } } n X| d k r | } n  | d k r | j } n  |
 d k r | j	 d | d |	  } n | j	 d | d |	 d |
  } |  j
 j |  j |  j d d d	 d
 \ } |  j
 j | g | g d | | | j   |  S(   s  Annotate the plot with a statistic about the relationship.

        *Deprecated and will be removed in a future version*.

        Parameters
        ----------
        func : callable
            Statistical function that maps the x, y vectors either to (val, p)
            or to val.
        template : string format template, optional
            The template must have the format keys "stat" and "val";
            if `func` returns a p value, it should also have the key "p".
        stat : string, optional
            Name to use for the statistic in the annotation, by default it
            uses the name of `func`.
        loc : string or int, optional
            Matplotlib legend location code; used to place the annotation.
        kwargs : key, value mappings
            Other keyword arguments are passed to `ax.legend`, which formats
            the annotation.

        Returns
        -------
        self : JointGrid instance.
            Returns `self`.

        sK   JointGrid annotation is deprecated and will be removed in a future release.s   {stat} = {val:.2g}; p = {p:.2g}t   ;t   statt   valt   pt	   linestyleRV   R   i    R'   N(   R   R   R   RM  RN  R6   R)   t   splitRq   R   RF  R^  R9   t   remove(   R   R   R  Ra  R'   R   R   t   default_templatet   outRb  Rc  t   _t
   annotationt   phantom(    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR
    s(    	*"
RV   c         K   s*   |  j  j | |  |  j  j | |  |  S(   s  Set the axis labels on the bivariate axes.

        Parameters
        ----------
        xlabel, ylabel : strings
            Label names for the x and y variables.
        kwargs : key, value mappings
            Other keyword arguments are passed to the set_xlabel or
            set_ylabel.

        Returns
        -------
        self : JointGrid instance
            returns `self`

        (   RF  RW   RX   (   R   RU  RV  R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   Z  s    c         O   s'   | j  d d  |  j j | |   d S(   s5   Wrap figure.savefig defaulting to tight bounding box.R   R   N(   R   R   R   (   R   R   R   (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   o  s    N(   Rq   Rr   Rs   R)   Rt   R   R^  RZ  RY  R
  R   R   (    (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR     s   		At   scattert   autog      @c         C   s  | d k	 r+ | }
 d } t j | t  n  t |  t j  s^ t d j d t	 |      n  | d k rs i  } n  | d k r i  } n  | d k r i  } n  | d k } t
 |  d | d | d | d | d	 | d
 | d | d |
 d | d | | 
} |	 d k	 rz| j d k rd } n t | j  } t |	 t  sF|	 g | }	 n  t |	  | k rgt d   n  i |	 d 6| _ n  | d k r| d k rd n d } n  | j   } | j r| d k r| j t j |  q| d k r| j d t  t | d <| j t |  qn  | j r5| d k	 r5| j } n	 | j } | d k rjd d l m } | | |  n, | d k rd d l m } | | |  n  | d k	 r| j   n  | S(   s  Plot pairwise relationships in a dataset.

    By default, this function will create a grid of Axes such that each
    variable in ``data`` will by shared in the y-axis across a single row and
    in the x-axis across a single column. The diagonal Axes are treated
    differently, drawing a plot to show the univariate distribution of the data
    for the variable in that column.

    It is also possible to show a subset of variables or plot different
    variables on the rows and columns.

    This is a high-level interface for :class:`PairGrid` that is intended to
    make it easy to draw a few common styles. You should use :class:`PairGrid`
    directly if you need more flexibility.

    Parameters
    ----------
    data : DataFrame
        Tidy (long-form) dataframe where each column is a variable and
        each row is an observation.
    hue : string (variable name), optional
        Variable in ``data`` to map plot aspects to different colors.
    hue_order : list of strings
        Order for the levels of the hue variable in the palette
    palette : dict or seaborn color palette
        Set of colors for mapping the ``hue`` variable. If a dict, keys
        should be values  in the ``hue`` variable.
    vars : list of variable names, optional
        Variables within ``data`` to use, otherwise use every column with
        a numeric datatype.
    {x, y}_vars : lists of variable names, optional
        Variables within ``data`` to use separately for the rows and
        columns of the figure; i.e. to make a non-square plot.
    kind : {'scatter', 'reg'}, optional
        Kind of plot for the non-identity relationships.
    diag_kind : {'auto', 'hist', 'kde'}, optional
        Kind of plot for the diagonal subplots. The default depends on whether
        ``"hue"`` is used or not.
    markers : single matplotlib marker code or list, optional
        Either the marker to use for all datapoints or a list of markers with
        a length the same as the number of levels in the hue variable so that
        differently colored points will also have different scatterplot
        markers.
    height : scalar, optional
        Height (in inches) of each facet.
    aspect : scalar, optional
        Aspect * height gives the width (in inches) of each facet.
    dropna : boolean, optional
        Drop missing values from the data before plotting.
    {plot, diag, grid}_kws : dicts, optional
        Dictionaries of keyword arguments.

    Returns
    -------
    grid : PairGrid
        Returns the underlying ``PairGrid`` instance for further tweaking.

    See Also
    --------
    PairGrid : Subplot grid for more flexible plotting of pairwise
               relationships.

    Examples
    --------

    Draw scatterplots for joint relationships and histograms for univariate
    distributions:

    .. plot::
        :context: close-figs

        >>> import seaborn as sns; sns.set(style="ticks", color_codes=True)
        >>> iris = sns.load_dataset("iris")
        >>> g = sns.pairplot(iris)

    Show different levels of a categorical variable by the color of plot
    elements:

    .. plot::
        :context: close-figs

        >>> g = sns.pairplot(iris, hue="species")

    Use a different color palette:

    .. plot::
        :context: close-figs

        >>> g = sns.pairplot(iris, hue="species", palette="husl")

    Use different markers for each level of the hue variable:

    .. plot::
        :context: close-figs

        >>> g = sns.pairplot(iris, hue="species", markers=["o", "s", "D"])

    Plot a subset of variables:

    .. plot::
        :context: close-figs

        >>> g = sns.pairplot(iris, vars=["sepal_width", "sepal_length"])

    Draw larger plots:

    .. plot::
        :context: close-figs

        >>> g = sns.pairplot(iris, height=3,
        ...                  vars=["sepal_width", "sepal_length"])

    Plot different variables in the rows and columns:

    .. plot::
        :context: close-figs

        >>> g = sns.pairplot(iris,
        ...                  x_vars=["sepal_width", "sepal_length"],
        ...                  y_vars=["petal_width", "petal_length"])

    Use kernel density estimates for univariate plots:

    .. plot::
        :context: close-figs

        >>> g = sns.pairplot(iris, diag_kind="kde")

    Fit linear regression models to the scatter plots:

    .. plot::
        :context: close-figs

        >>> g = sns.pairplot(iris, kind="reg")

    Pass keyword arguments down to the underlying functions (it may be easier
    to use :class:`PairGrid` directly):

    .. plot::
        :context: close-figs

        >>> g = sns.pairplot(iris, diag_kind="kde", markers="+",
        ...                  plot_kws=dict(s=50, edgecolor="b", linewidth=1),
        ...                  diag_kws=dict(shade=True))

    sK   The `size` parameter has been renamed to `height`; pleaes update your code.s8   'data' must be pandas DataFrame object, not: {typefound}t	   typefoundt   histR&  R  R  Rj   Rk   Rl   R  Rw   Rx   R   i   sS   markers must be a singleton or a list of markers for each level of the hue variablet   markerRm  t   kdet   shadeR9   Rl  (   t   scatterplott   reg(   t   regplotN(    R)   R   R   R   Rh   R!  R-  R6   R   t   typeR   R+   Rf   R,   R   R   R   R  R9  R   Ro  R   Rt   R8   R
   R>  R.   t
   relationalRs  t
   regressionRu  RU   (   Ra   Rj   Rk   Rl   R&  R  R  t   kindt	   diag_kindt   markersRw   Rx   R   t   plot_kwst   diag_kwst   grid_kwsR$   R   R  RL  t	   n_markerst   plotterRs  Ru  (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   u  sd    				!		
	i   i   g?c         K   s  d | k r4 | j  d  } d } t j | t  n  | d k rI i  } n  | j |  | d k rk i  } n  | d k r i  } n  | d k r t   d } n  t j j	 j
 |  } g  t j d d d  D] } t j | d | ^ q } t | d t } t |  | | d |	 d	 | d
 | d | d |
 d | } | d k r| j d |  | j t j |  | j d t  | j d |  | j t |  nh| j d  rRt t | j  d  } t t | j  d  } t t j | | g   } | j d |  | j d |  | j t j  |  | j d t  | j d |  | j t |  n| j d  r| j d t  | j d |  | j t! |  | j d t  | j d |  | j t! |  n6| j d  r&d d l" m# } | j d |  | j t |  | j d |  | j | |  n | j d  rd d l" m$ } | j d |  | j | |  | j% j& d j'   j( \ }  } | j d |  | j d t  t |  d | j) | t | d t d t* j+ d | j, | d } n d } t- |   | d k	 r| j. | |  n  | S(   s  Draw a plot of two variables with bivariate and univariate graphs.

    This function provides a convenient interface to the :class:`JointGrid`
    class, with several canned plot kinds. This is intended to be a fairly
    lightweight wrapper; if you need more flexibility, you should use
    :class:`JointGrid` directly.

    Parameters
    ----------
    x, y : strings or vectors
        Data or names of variables in ``data``.
    data : DataFrame, optional
        DataFrame when ``x`` and ``y`` are variable names.
    kind : { "scatter" | "reg" | "resid" | "kde" | "hex" }, optional
        Kind of plot to draw.
    stat_func : callable or None, optional
        *Deprecated*
    color : matplotlib color, optional
        Color used for the plot elements.
    height : numeric, optional
        Size of the figure (it will be square).
    ratio : numeric, optional
        Ratio of joint axes height to marginal axes height.
    space : numeric, optional
        Space between the joint and marginal axes
    dropna : bool, optional
        If True, remove observations that are missing from ``x`` and ``y``.
    {x, y}lim : two-tuples, optional
        Axis limits to set before plotting.
    {joint, marginal, annot}_kws : dicts, optional
        Additional keyword arguments for the plot components.
    kwargs : key, value pairings
        Additional keyword arguments are passed to the function used to
        draw the plot on the joint Axes, superseding items in the
        ``joint_kws`` dictionary.

    Returns
    -------
    grid : :class:`JointGrid`
        :class:`JointGrid` object with the plot on it.

    See Also
    --------
    JointGrid : The Grid class used for drawing this plot. Use it directly if
                you need more flexibility.

    Examples
    --------

    Draw a scatterplot with marginal histograms:

    .. plot::
        :context: close-figs

        >>> import numpy as np, pandas as pd; np.random.seed(0)
        >>> import seaborn as sns; sns.set(style="white", color_codes=True)
        >>> tips = sns.load_dataset("tips")
        >>> g = sns.jointplot(x="total_bill", y="tip", data=tips)

    Add regression and kernel density fits:

    .. plot::
        :context: close-figs

        >>> g = sns.jointplot("total_bill", "tip", data=tips, kind="reg")

    Replace the scatterplot with a joint histogram using hexagonal bins:

    .. plot::
        :context: close-figs

        >>> g = sns.jointplot("total_bill", "tip", data=tips, kind="hex")

    Replace the scatterplots and histograms with density estimates and align
    the marginal Axes tightly with the joint Axes:

    .. plot::
        :context: close-figs

        >>> iris = sns.load_dataset("iris")
        >>> g = sns.jointplot("sepal_width", "petal_length", data=iris,
        ...                   kind="kde", space=0, color="g")

    Draw a scatterplot, then add a joint density estimate:

    .. plot::
        :context: close-figs

        >>> g = (sns.jointplot("sepal_length", "sepal_width",
        ...                    data=iris, color="k")
        ...         .plot_joint(sns.kdeplot, zorder=0, n_levels=6))

    Pass vectors in directly without using Pandas, then name the axes:

    .. plot::
        :context: close-figs

        >>> x, y = np.random.randn(2, 300)
        >>> g = (sns.jointplot(x, y, kind="hex")
        ...         .set_axis_labels("x", "y"))

    Draw a smaller figure with more space devoted to the marginal plots:

    .. plot::
        :context: close-figs

        >>> g = sns.jointplot("total_bill", "tip", data=tips,
        ...                   height=5, ratio=3, color="g")

    Pass keyword arguments down to the underlying plots:

    .. plot::
        :context: close-figs

        >>> g = sns.jointplot("petal_length", "sepal_length", data=iris,
        ...                   marginal_kws=dict(bins=15, rug=True),
        ...                   annot_kws=dict(stat="r"),
        ...                   s=40, edgecolor="w", linewidth=1)

    R$   sJ   The `size` paramter has been renamed to `height`; please update your code.i    i   i   RK   t   as_cmapR   Rw   RQ  RR  R{   R|   Rl  R   Rq  t   hexi2   t   gridsizet   cmapRr  Rt  (   Ru  t   resid(   t	   residplotR   R_  t   fits>   kind must be either 'scatter', 'reg', 'resid', 'kde', or 'hex'N(/   R   R   R   R   R)   R_   R   R0   Rn   t   colorConvertert   to_rgbR   t   linspaceR   t   set_hls_valuesR   Rt   R   R   RZ  R   Rl  R8   RY  R	   R   t   minR   RM  RN  R   t   meant   hexbinR
   Rx  Ru  R  RF  t   collectionst   get_offsetst   TRG  R   t   normRH  R   R
  (   RM  RN  Ra   Ry  t	   stat_funcR   Rw   RQ  RR  R   R{   R|   t	   joint_kwst   marginal_kwst	   annot_kwsR   R   t	   color_rgbRK   Rn   R  RL  t   x_binst   y_binsR  Ru  R  (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyR   U  s    }			4	(+   t
   __future__R    t	   itertoolsR   t   distutils.versionR   R   t   textwrapR   t   numpyR   t   pandasR!  t   scipyR   R   R0   t   matplotlib.pyplott   pyplotR   RV   R   t   palettesR   R   t   external.sixR   t   distributionsR	   R
   R   t   __all__R   R   Ri   R  R   R   R   R)   Rt   R   R   (    (    (    s/   lib/python2.7/site-packages/seaborn/axisgrid.pyt   <module>   sb   							   e  u						