a
    SicU                    @  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Zd dlmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZmZmZmZ ddlmZm Z  ddl!m"Z"m#Z# g dZ$e"j%e#d dZ&G dd dZ'G dd de'Z(e)edededededededededededdZ*G d d! d!e(Z+G d"d# d#e(Z,G d$d% d%e'Z-d&j.e&e#d' e#d( d)e-j/_0ddddddd*d+dd,dd-d-ddddd.d/d0Z1d8dddd*d1d2d3d-ddddddd-ddd4d5d6Z2d7j.e&e#d' e#d( d)e2_0dS )9    )annotations)product)	signatureN)dedent   )VectorPlottervariable_typecategorical_order)
share_axis)utils)adjust_legend_subtitles_check_argument_draw_figure_disable_autolayout)color_paletteblend_palette)DocstringComponents
_core_docs)	FacetGridPairGrid	JointGridpairplot	jointplotparams)corec                   @  sH   e Zd ZdZdd Zedd Zedd Zdd	 Zd
d Z	dd Z
dS )	_BaseGridz!Base class for grids of subplots.c                 K  s*   | j jD ]}|dur|jf i | q| S )z$Set attributes on each subplot Axes.N)axesflatset)selfkwargsax r"   L/var/www/html/django/DPS/env/lib/python3.9/site-packages/seaborn/axisgrid.pyr   #   s    z_BaseGrid.setc                 C  s   | j S )z)DEPRECATED: prefer the `figure` property._figurer   r"   r"   r#   fig*   s    z_BaseGrid.figc                 C  s   | j S )zHAccess the :class:`matplotlib.figure.Figure` object underlying the grid.r$   r&   r"   r"   r#   figure3   s    z_BaseGrid.figurec                 O  s   || g|R i | | S )ax  
        Pass the grid to a user-supplied function and return self.

        The `func` must accept an object of this type for its first
        positional argument. Additional arguments are passed through.
        The return value of `func` is ignored; this method returns self.
        See the `pipe` method if you want the return value.

        Added in v0.12.0.

        r"   r   funcargsr    r"   r"   r#   apply8   s    z_BaseGrid.applyc                 O  s   || g|R i |S )a  
        Pass the grid to a user-supplied function and return its value.

        The `func` must accept an object of this type for its first
        positional argument. Additional arguments are passed through.
        The return value of `func` becomes the return value of this method.
        See the `apply` method if you want to return self instead.

        Added in v0.12.0.

        r"   r)   r"   r"   r#   pipeG   s    z_BaseGrid.pipec                 O  s*   |  }|dd | jj|i | dS )z
        Save an image of the plot.

        This wraps :meth:`matplotlib.figure.Figure.savefig`, using bbox_inches="tight"
        by default. Parameters are passed through to the matplotlib function.

        bbox_inchestightN)copy
setdefaultr(   savefigr   r+   r    r"   r"   r#   r2   U   s    z_BaseGrid.savefigN)__name__
__module____qualname____doc__r   propertyr'   r(   r,   r-   r2   r"   r"   r"   r#   r       s   

r   c                   @  sX   e Zd ZdZdZdZdd Zdd Zdd	d
Zdd Z	dd Z
edd ZdddZdS )Gridz>A grid that can have multiple subplots and an external legend.FTc                 C  s   g d| _ d | _d| _d S )N)r   r   r   r   F)_tight_layout_rect_tight_layout_pad_extract_legend_handlesr&   r"   r"   r#   __init__g   s    
zGrid.__init__c                 O  sD   |  }|d| j | jdur.|d| j | jj|i | | S )z:Call fig.tight_layout within rect that exclude the legend.rectNpad)r0   r1   r:   r;   r%   tight_layoutr3   r"   r"   r#   r@   p   s    
zGrid.tight_layoutNc                   s  du r| j |du r@| jdu r.t }ntttj| j}tjj	ddd  fdd|D }|du rr| j
n|}tjd }g }|D ]&}	t|	tr|	\}
}n|	}|| q|dd | jr|d	d
 |dd | jj||fi |}|| _|j|d|id |rt| t| j | j| jj }| j \}}| j|| | t| j | j| jj }|||  }| jrdnd}|| | _d| j }| jj|d || jd< nR| j j!d }|dd |j||fi |}|j|d|id || _|rt| | S )a  Draw a legend, maybe placing it outside axes and resizing the figure.

        Parameters
        ----------
        legend_data : dict
            Dictionary mapping label names (or two-element tuples where the
            second element is a label name) to matplotlib artist handles. The
            default reads from ``self._legend_data``.
        title : string
            Title for the legend. The default reads from ``self._hue_var``.
        label_order : list of labels
            The order that the legend entries should appear in. The default
            reads from ``self.hue_names``.
        adjust_subtitles : bool
            If True, modify entries with invisible artists to left-align
            the labels and set the font size to that of a title.
        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.

        Nr   )alpha	linewidthc                   s   g | ]} | qS r"   )get.0lZblank_handlelegend_datar"   r#   
<listcomp>       z#Grid.add_legend.<locals>.<listcomp>zlegend.title_fontsizescatterpointsr   frameonFloczcenter rightsize)propg{Gz?{Gz?)right   best)"_legend_data	hue_nameslistkeysmapr   to_utf8mplpatchesPatch_hue_varrcParams
isinstancetupleappendr1   _legend_outr%   legend_legend	set_titler   r   get_window_extentwidthdpiget_size_inchesset_size_inches_margin_titlesZ_space_neededsubplots_adjustr:   r   r   )r   rH   titlelabel_orderadjust_subtitlesr    handlesZ
title_sizelabelsentry_label	figlegendZlegend_widthZ	fig_width
fig_heightZspace_neededmarginrQ   r!   legr"   rG   r#   
add_legendy   sZ    







zGrid.add_legendc                 C  s   i }|j durH| jrH|j j}dd |j jD }|dd t||D  | \}}|dd t||D  | j| d|_ dS )z8Extract the legend data from an axes object and save it.Nc                 S  s   g | ]}|  qS r"   get_text)rE   tr"   r"   r#   rI      rJ   z,Grid._update_legend_data.<locals>.<listcomp>c                 S  s   i | ]\}}||qS r"   r"   rE   hrF   r"   r"   r#   
<dictcomp>   rJ   z,Grid._update_legend_data.<locals>.<dictcomp>c                 S  s   i | ]\}}||qS r"   r"   r}   r"   r"   r#   r      rJ   )legend_r<   legendHandlestextsupdatezipget_legend_handles_labelsrT   )r   r!   datarp   rq   r"   r"   r#   _update_legend_data   s    zGrid._update_legend_datac           
        s   |du rt dd nt|| |}t|} du r^t }|t|krRt d|}qt |d}n2t tr fdd|D }	t |	|}n
t  |}t ||  S )z*Get a list of colors for the hue variable.Nr   )n_colorshuslc                   s   g | ]} | qS r"   r"   )rE   r~   paletter"   r#   rI     rJ   z%Grid._get_palette.<locals>.<listcomp>)r   r	   lenr   get_color_cycler_   dict)
r   r   hue	hue_orderr   rU   r   Zcurrent_palettecolorscolor_namesr"   r   r#   _get_palette   s    


zGrid._get_palettec                 C  s"   z| j W S  ty   Y dS 0 dS )z9The :class:`matplotlib.legend.Legend` object, if present.N)rd   AttributeErrorr&   r"   r"   r#   rc     s    zGrid.legendbothc                 K  s&   | j jD ]}|jf d|i| q| S )a  Modify the ticks, tick labels, and gridlines.

        Parameters
        ----------
        axis : {'x', 'y', 'both'}
            The axis on which to apply the formatting.
        kwargs : keyword arguments
            Additional keyword arguments to pass to
            :meth:`matplotlib.axes.Axes.tick_params`.

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

        axis)r(   r   tick_params)r   r   r    r!   r"   r"   r#   r     s    zGrid.tick_params)NNNF)r   )r4   r5   r6   r7   rk   rb   r=   r@   ry   r   r   r8   rc   r   r"   r"   r"   r#   r9   b   s   		  
h
r9   z    data : DataFrame
        Tidy ("long-form") dataframe where each column is a variable and each
        row is an observation.    zq    row, col : vectors or keys in ``data``
        Variables that define subsets to plot on different facets.    z    {row,col}_order : vector of strings
        Specify the order in which levels of the ``row`` and/or ``col`` variables
        appear in the grid of subplots.    z    col_wrap : int
        "Wrap" the column variable at this width, so that the column facets
        span multiple rows. Incompatible with a ``row`` facet.    z    share{x,y} : bool, 'col', or 'row' optional
        If true, the facets will share y axes across columns and/or x axes
        across rows.    zW    height : scalar
        Height (in inches) of each facet. See also: ``aspect``.    z    aspect : scalar
        Aspect ratio of each facet, so that ``aspect * height`` gives the width
        of each facet in inches.    a      palette : palette name, list, or dict
        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.    z    legend_out : bool
        If ``True``, the figure size will be extended, and the legend will be
        drawn outside the plot on the center right.    z    margin_titles : bool
        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.    zU    facet_kws : dict
        Additional parameters passed to :class:`FacetGrid`.
    )r   rowcolZrowcol_ordercol_wrapZshare_xyheightaspectr   
legend_outmargin_titles	facet_kwsc                      sV  e Zd ZdZdddddddddddddddddddddd fdd	
Zed
jf i ee_dd Zdd Z	dd Z
dd Zdd Zdd Zd<ddZdd Zd=ddZd>ddZd?dd Zd@d!d"ZdAd#d$ZdBd%d&Zddd'd(d)d*d+Zed,d- Zed.d/ Zed0d1 Zed2d3 Zed4d5 Zed6d7 Zed8d9 Zed:d; Z  Z S )Cr   z7Multi-plot grid for plotting conditional relationships.NT   r   F)rowcolr   r   sharexshareyr   r   r   	row_order	col_orderr   hue_kwsdropnar   despiner   xlimylimsubplot_kwsgridspec_kwsc          .        s  t    |}|d u rd }nt|| |}| ||||
}|d u rHg }nt|| |}|d u rdg }nt|| |}|d ur~|ni }tt|t}|r|d u r|n
||  }|d u r|n
||  }|d u r|n
||  }||B |B  } n| } |d u rdnt|}!|d u rdnt|}"|!|" | _	|| _
|d urj|d urPd}#t|#|}!ttt|| }"|!| _|"| _|!| |	 |"| f}$|d urd}|d u ri n| }|d u ri n| }|d ur||d< |d ur||d< t  tj|$d}%W d    n1 s0    Y  |d u rtd||||d}&|%j|"|!fi |&}'|d u rf|d u rfi }(nR|d u rtt||'j}(n6|d u rtt||'j}(nt||})tt|)|'j}(n|rtd t|}*t|*t}'|%j|"|!dfi ||'d	< |r
|'d	 |d
< |r|'d	 |d< td|*D ]$}+|%j|"|!|+d fi ||'|+< q&tt||'}(|%| _|'| _ |(| _!d | _"|| _#|| _$|| _%|| _&|| _'|"| _|| _(|!| _|| _)|| _*g | _+|| _
|| _,|| _-|| _.i | _/d | _0d | _1|| _2|| _3|| _4| | _5| 6  | 7  |r| 8  |dv rb| j9D ]<},|,: D ]}-|-;d q0|,j<j=;d |,j<j>;d q$|dv r| j?D ]<},|,@ D ]}-|-;d q~|,jAj=;d |,jAj>;d qrd S )Nr   z)Cannot use `row` and `col_wrap` together.Fr   r   figsize)squeezer   r   
subplot_kwgridspec_kwz,`gridspec_kws` ignored when using `col_wrap`r   r   r   )Tr   )Tr   )Bsuperr=   r	   r   npzerosr   boolisnull	_n_facets	_col_wrap
ValueErrorintceil_ncol_nrowr0   r   pltr(   r   subplotsr   r   r   warningswarnemptyobjectadd_subplotranger%   _axes
_axes_dictrd   r   	row_names	col_namesrU   r   _row_var_col_varrk   _margin_titles_textsr]   _colorsrb   rT   _x_var_y_var_sharex_sharey_dropna_not_na
set_titlesr@   r   _not_bottom_axesget_xticklabelsset_visiblexaxis
offsetTextrt   _not_left_axesget_yticklabelsyaxis).r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zhue_varrU   r   r   r   Znone_naZrow_naZcol_naZhue_nanot_nancolnrowerrr   r'   r    r   	axes_dictZfacet_productZn_axesir!   rt   	__class__r"   r#   r=   n  s    







,




"



zFacetGrid.__init__a?          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 variable with the ``hue``
        parameter, which plots different subsets 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.

        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.

        .. warning::

            When using seaborn functions that infer semantic mappings from a
            dataset, care must be taken to synchronize those mappings across
            facets (e.g., by defining the ``hue`` mapping with a palette dict or
            setting the data type of the variables to ``category``). 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.

        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 ``{{var}}_order`` parameters to
            control the order of levels of this variable.
        {col_wrap}
        {share_xy}
        {height}
        {aspect}
        {palette}
        {{row,col,hue}}_order : lists
            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
            Remove the top and right spines from the plots.
        {margin_titles}
        {{x, y}}lim: tuples
            Limits for each of the axes on each facet (only relevant when
            share{{x, y}} is True).
        subplot_kws : dict
            Dictionary of keyword arguments passed to matplotlib subplot(s)
            methods.
        gridspec_kws : dict
            Dictionary of keyword arguments passed to
            :class:`matplotlib.gridspec.GridSpec`
            (via :meth:`matplotlib.figure.Figure.subplots`).
            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`
        displot : Combine a distribution plot and a :class:`FacetGrid`
        catplot : Combine a categorical plot and a :class:`FacetGrid`
        lmplot : Combine a regression plot and a :class:`FacetGrid`

        Examples
        --------

        .. note::

            These examples use seaborn functions to demonstrate some of the
            advanced features of the class, but in most cases you will want
            to use figue-level functions (e.g. :func:`displot`, :func:`relplot`)
            to make the plots shown here.

        .. include:: ../docstrings/FacetGrid.rst

        c                 #  s   j  jr$ fddjD }ntdtj g}jrV fddjD }ntdtj g}jr fddjD }ntdtj g}tt|t|t|D ]<\\}}\}}\}}	 ||@ |	@ j	@  }
|||f|
fV  qdS )a  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.

        c                   s   g | ]} j  |kqS r"   )r   rE   nr   r   r"   r#   rI     rJ   z(FacetGrid.facet_data.<locals>.<listcomp>Tc                   s   g | ]} j  |kqS r"   )r   r   r   r"   r#   rI     rJ   c                   s   g | ]} j  |kqS r"   )r]   r   r   r"   r#   rI     rJ   N)
r   r   r   repeatr   r   rU   r   	enumerater   )r   Z	row_masksZ	col_masksZ	hue_masksr   r   jr   kr   data_ijkr"   r   r#   
facet_data}  s     zFacetGrid.facet_datac                 O  sd  | dd}tt|dd}|dkrld|vrBd|j}t| t|dkrld	|vrld
|j}t| |  D ]\\}}}	}
|
j	j
sqt|d }| |||}| |	||d< | j D ]\}}||	 ||< q| jdurt| j|	 |d< |
t| }| jr| }dd | D }|dr<dd |D }| |||| qt| |dd  | S )a=  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.

        colorNr5    zseaborn.categoricalorderzXUsing the {} function without specifying `order` is likely to produce an incorrect plot.r   r   z\Using the {} function without specifying `hue_order` is likely to produce an incorrect plot.seabornrt   c                 S  s   g | ]\}}|qS r"   r"   )rE   r   vr"   r"   r#   rI     rJ   z!FacetGrid.map.<locals>.<listcomp>
matplotlibc                 S  s   g | ]
}|j qS r"   )values)rE   r   r"   r"   r#   rI     rJ   rR   )popstrgetattrformatr4   r   r   r   r   r   rN   
startswith
facet_axis_facet_colorr   itemsr]   r   rY   rU   rV   r   r   _facet_plot_finalize_grid)r   r*   r+   r    kw_colorZfunc_modulewarningrow_icol_jhue_kr   modify_stater!   kwval_list	plot_data	plot_argsr"   r"   r#   rX     s@    


zFacetGrid.mapc                 O  s  | dd}|  D ]\\}}}}|jjs,qt|jd }	| |||	}
| |||d< | j	
 D ]\}}|| ||< qf| jdur| j| |d< | jr| }||d< | ||
|| q|dd|ddg}t|dd D ]\}}|||< q| | | S )	at  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   Nr   rt   r   xyrR   )r   r   r   rN   r   r5   r   r   r   r   r   r]   rU   r   r   r   rC   r   r   )r   r*   r+   r    r   r  r  r  r   r  r!   r  r  axis_labelsr   valr"   r"   r#   map_dataframe  s(    


zFacetGrid.map_dataframec                 C  s&   | j | }|d ur|S |d ur"|S d S N)r   )r   Z	hue_indexr   r   r"   r"   r#   r   >  s
    
zFacetGrid._facet_colorc                 C  sd   t |jdrH| }g d}t||D ]\}}|||< q*g }||d< ||i | | | d S )Nr   )r	  r
  r   rN   styler!   )r   r5   r   r0   r   r   )r   r*   r!   r  plot_kwargs	semanticskeyr  r"   r"   r#   r   F  s    
zFacetGrid._facet_plotc                 C  s   | j |  |   dS )z$Finalize the annotations and layout.N)set_axis_labelsr@   )r   Zaxlabelsr"   r"   r#   r   U  s    
zFacetGrid._finalize_gridc                 C  s8   | j dur| jj| }n| j||f }|r4t| |S )z?Make the axis identified by these indices active and return it.N)r   r   r   r   sca)r   r  r  r  r!   r"   r"   r#   r   Z  s    

zFacetGrid.facet_axisc                 K  s   t j| jfi | | S )z#Remove axis spines from the facets.)r   r   r%   )r   r    r"   r"   r#   r   h  s    zFacetGrid.despinec                 K  sL   |dur$|| _ | j|fd|i| |durH|| _| j|fd|i| | S )z>Set axis labels on the left column and bottom row of the grid.Nclear_inner)r   set_xlabelsr   set_ylabels)r   x_vary_varr  r    r"   r"   r#   r  m  s    zFacetGrid.set_axis_labelsc                 K  sJ   |du r| j }| jD ]}|j|fi | q|rF| jD ]}|d q6| S )z/Label the x axis on the bottom row of the grid.Nr   )r   _bottom_axes
set_xlabelr   r   rt   r  r    r!   r"   r"   r#   r  x  s    

zFacetGrid.set_xlabelsc                 K  sJ   |du r| j }| jD ]}|j|fi | q|rF| jD ]}|d q6| S )z0Label the y axis on the left column of the grid.Nr   )r   
_left_axes
set_ylabelr   r  r"   r"   r#   r    s    

zFacetGrid.set_ylabelsc                 K  s   | j jD ]}| }|| |du r~dd | D }|durj| dd| }|dd| }|| |j|fi | q|j|fi | q| S )z#Set x axis tick labels of the grid.Nc                 S  s   g | ]}|  qS r"   rz   rD   r"   r"   r#   rI     rJ   z-FacetGrid.set_xticklabels.<locals>.<listcomp>)r   r   
get_xticks
set_xticksr   set_xticklabels)r   rq   stepr    r!   
curr_tickscurr_labelsxticksr"   r"   r#   r!    s    

zFacetGrid.set_xticklabelsc                 K  sd   | j jD ]V}| }|| |du rLdd | D }|j|fi | q|j|fi | q| S )z6Set y axis tick labels on the left column of the grid.Nc                 S  s   g | ]}|  qS r"   rz   rD   r"   r"   r#   rI     rJ   z-FacetGrid.set_yticklabels.<locals>.<listcomp>)r   r   
get_yticks
set_yticksr   set_yticklabels)r   rq   r    r!   r#  r$  r"   r"   r#   r(    s    
zFacetGrid.set_yticklabelsc              	   K  s  t | j| jd}|dtjd |d< |du r2d}|du r>d}|du rt| jdu rV|}n| jdu rf|}nd||g}t|}t|}t|}| j	r| j
D ]}|  qg | _
| jdur,t| jD ]`\}}| j|df }	|t |d	 |jf i |}
|	j|
fd
ddddd|}| j
| q| jdurt| jD ]F\}}|t |d |jf i |}
| jd|f j|
fi | qB| S | jdur| jdurt| jD ]^\}}t| jD ]H\}}|t ||d |jf i |}
| j||f j|
fi | qqn| jdur~t| jr~t| jD ]F\}}|t |d	 |jf i |}
| j|df j|
fi | q4nh| jdurt| jrt| jD ]D\}}|t |d |jf i |}
| jj| j|
fi | q| S )a  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.

        )Zrow_varZcol_varrN   zaxes.labelsizeNz{row_var} = {row_name}z{col_var} = {col_name}z | )row_name)gRQ?      ?zaxes fractioni  leftcenter)xyxycoordsrotationhava)col_namer   )r*  r3  )r   r   r   r   rZ   r^   joinr   rY   rk   r   remover   r   r   r   r   annotatera   r   re   r   r   )r   templateZrow_templateZcol_templater    r+   textr   r*  r!   rm   r   r3  r"   r"   r#   r     sp    






 &"zFacetGrid.set_titles.5--)r	  r
  r   	linestylec                K  sT   ||d< ||d< |dur0| j tjfd|i| |durP| j tjfd|i| | S )a  Add a reference line(s) to each facet.

        Parameters
        ----------
        x, y : numeric
            Value(s) to draw the line(s) at.
        color : :mod:`matplotlib color <matplotlib.colors>`
            Specifies the color of the reference line(s). Pass ``color=None`` to
            use ``hue`` mapping.
        linestyle : str
            Specifies the style of the reference line(s).
        line_kws : key, value mappings
            Other keyword arguments are passed to :meth:`matplotlib.axes.Axes.axvline`
            when ``x`` is not None and :meth:`matplotlib.axes.Axes.axhline` when ``y``
            is not None.

        Returns
        -------
        :class:`FacetGrid` instance
            Returns ``self`` for easy method chaining.

        r   r;  Nr	  r
  )rX   r   axvlineaxhline)r   r	  r
  r   r;  line_kwsr"   r"   r#   refline  s    zFacetGrid.reflinec                 C  s   | j S )zBAn array of the :class:`matplotlib.axes.Axes` objects in the grid.)r   r&   r"   r"   r#   r   *  s    zFacetGrid.axesc                 C  s&   | j jdkr| j d S d}t|dS )zJThe :class:`matplotlib.axes.Axes` when no faceting variables are assigned.)r   r   )r   r   z<Use the `.axes` attribute when facet variables are assigned.N)r   shaper   )r   r   r"   r"   r#   r!   /  s
    
zFacetGrid.axc                 C  s   | j S )a1  A mapping of facet names to corresponding :class:`matplotlib.axes.Axes`.

        If only one of ``row`` or ``col`` is assigned, each key is a string
        representing a level of that variable. If both facet dimensions are
        assigned, each key is a ``({row_level}, {col_level})`` tuple.

        )r   r&   r"   r"   r#   r   :  s    	zFacetGrid.axes_dictc                 C  s   | j du r"| jddddf jS g }| j| j | j }t| jD ]L\}}|| j o~|| j| jd  k o~|| j| jd  | k }|rB|| qBt	|t
jS dS )z&Return a flat array of the inner axes.Nr)  r   r   r   r   r   r   r   r   ra   r   arrayr   r   r   Zn_emptyr   r!   ra   r"   r"   r#   _inner_axesG  s    

zFacetGrid._inner_axesc                 C  s\   | j du r| jdddf jS g }t| jD ]\}}|| j s,|| q,t|tjS dS )z/Return a flat array of the left column of axes.Nr   	r   r   r   r   r   ra   r   rB  r   r   r   r   r!   r"   r"   r#   r  Y  s    

zFacetGrid._left_axesc                 C  s`   | j du r"| jddddf jS g }t| jD ]\}}|| j r0|| q0t|tjS dS )z;Return a flat array of axes that aren't on the left column.Nr   rE  rF  r"   r"   r#   r   e  s    

zFacetGrid._not_left_axesc                 C  s   | j du r| jdddf jS g }| j| j | j }t| jD ]B\}}|| j| jd  kpp|| j| jd  | k}|r>|| q>t	|t
jS dS )z.Return a flat array of the bottom row of axes.Nr)  r   rA  rC  r"   r"   r#   r  q  s    
zFacetGrid._bottom_axesc                 C  s   | j du r"| jddddf jS g }| j| j | j }t| jD ]B\}}|| j| jd  k ot|| j| jd  | k }|rB|| qBt	|t
jS dS )z:Return a flat array of axes that aren't on the bottom row.Nr)  r   rA  rC  r"   r"   r#   r     s    
zFacetGrid._not_bottom_axes)T)NNT)NT)NT)NN)N)NNN)!r4   r5   r6   r7   r=   r   r   _facet_docsr   rX   r  r   r   r   r   r   r  r  r  r!  r(  r   r?  r8   r   r!   r   rD  r  r   r  r   __classcell__r"   r"   r   r#   r   k  sV   
 4Z\(RG






\$







r   c                      s   e Zd ZdZddddddddddddddd fd	d

Zdd Zdd Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd  Z  ZS )!r   aI  Subplot grid for plotting pairwise relationships in a dataset.

    This object 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
    marginal distribution of each variable can be shown on the diagonal.

    Several different common plots can be generated in a single line using
    :func:`pairplot`. Use :class:`PairGrid` when you need more flexibility.

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

    NFT      @r   r+  )r   varsx_varsy_varsr   r   r   cornerdiag_shareyr   r   
layout_padr   r   c                  sB  t    | |}||v r&|| |dur>t|}t|}|du rJ|}|du rV|}t|rf|g}t|rv|g}t| | _}t| | _}| j| jk| _	|st
d|st
dt|| | t|| f}t  tj|d}W d   n1 s0    Y  |jt|t|dddd}|	| _|	rjt|d	}t| D ]&\}}|||f   d|||f< qB|| _|| _|| _|
| _d| _d| _|| _|   || _|du rd
g | _}tjd
gt| |jd| _ n8t!|| | }}|rtt"tj#|}|| _|| | _ |dur|ni | _$|| _%|| _&| '||||| _(i | _)|ddddf j*D ]J}|du rnq\|+ D ]}|,d qv|j-j.,d |j-j/,d q\|ddd	df j*D ]J}|du rАq|0 D ]}|,d q|j1j.,d |j1j/,d qg d| _2|| _3|| _4|r2t5j6|d | j7|d dS )ac  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)
            Variable in ``data`` to map plot aspects to different colors. This
            variable will be excluded from the default x and y variables.
        vars : list of variable names
            Variables within ``data`` to use, otherwise use every column with
            a numeric datatype.
        {x, y}_vars : lists of variable names
            Variables within ``data`` to use separately for the rows and
            columns of the figure; i.e. to make a non-square plot.
        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).
        corner : bool
            If True, don't add axes to the upper (off-diagonal) triangle of the
            grid, making this a "corner" plot.
        height : scalar
            Height (in inches) of each facet.
        aspect : scalar
            Aspect * height gives the width (in inches) of each facet.
        layout_pad : scalar
            Padding between axes; passed to ``fig.tight_layout``.
        despine : boolean
            Remove the top and right spines from the plots.
        dropna : boolean
            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
        --------

        .. include:: ../docstrings/PairGrid.rst

        Nz$No variables found for grid columns.z!No variables found for grid rows.r   r   r   F)r   r   r   r   
_nolegend_)indexr)  )rP   rP   Gz?rR  )r'   )r?   )8r   r=   _find_numeric_colsr5  rV   r   isscalarrK  rL  square_gridr   r   r   r   r(   r   _cornertriu_indices_fromr   r%   r   r   rN  	diag_vars	diag_axesr   _add_axis_labelsr]   rU   pdSeriesrQ  hue_valsr	   filternotnullr   _orig_palette
_hue_orderr   r   rT   r   r   r   r   r   rt   r   r   r:   r;   _despiner   r   r@   )r   r   r   rJ  rK  rL  r   r   r   rM  rN  r   r   rO  r   r   numeric_colsr   r'   r   Zhide_indicesr   r   rU   r!   rt   r   r"   r#   r=     s    8




*	





zPairGrid.__init__c                 K  s8   t | jj\}}t|j|j}| j||fi | | S )aM  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   indicesr   r@  r   r   _map_bivariate)r   r*   r    row_indicescol_indicesrd  r"   r"   r#   rX   P  s    zPairGrid.mapc                 K  s*   t t| jd }| j||fi | | S )a^  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)  )r   r   tril_indices_fromr   re  r   r*   r    rd  r"   r"   r#   	map_lowera  s    zPairGrid.map_lowerc                 K  s*   t t| jd }| j||fi | | S )a^  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   )r   r   rW  r   re  ri  r"   r"   r#   	map_upperp  s    zPairGrid.map_upperc                 K  s   | j r2| j|fi | | js| j|fi | nVg }t| jD ]2\}}t| jD ]\}}||krR|||f qRq@| j||fi | | S )a\  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``.

        )	rU  rj  rV  rk  r   rL  rK  ra   re  )r   r*   r    rd  r   r  r   r  r"   r"   r#   map_offdiag  s    zPairGrid.map_offdiagc                 K  s.  | j du rg }g }t| jD ]\}}t| jD ]\}}||kr0|| | j||f }	|	 }
|
  ||
 tj	
dds|	jjD ]}|jd q| jr0|	jd | jr0tj|	dd q0q| jr|r|dd D ]}	t|d |	d qt|tj| _t|tj| _ d	t|jvr2| j|fi |S t| j| j D ]\}}	| }t|j d
rl|	|d< n
t!|	 | j"| }| j#dur| j"| j# }nd}| j$r|% }|dur||% M }|| }|dur|| }|&d	| |&d| j' |&d| j( |f d|i| d|	_)q@| *  | S )aY  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``.

        Nz
ytick.leftTFr!   r,  r   r   r
  r   r   r!   r   r   r	  )+rY  r   rL  rK  ra   r   twinxset_axis_offr   r^   rC   r   
majorTicks	tick1liner   rV  rb  r   r   rN  r
   r   rB  object_rX  r   
parameters_map_diag_iter_huer   r0   r   r5   r   r  r   r]   r   notnar1   ra  r`  r   rZ  )r   r*   r    rX  rY  r   r  r   r  r!   Zdiag_axtickvarr  vectorr   r   r"   r"   r#   map_diag  s`    








zPairGrid.map_diagc              
   K  s  | dd}t| j| jD ]\}}| j| | j}| }t|j	
drV||d< n
t| t| jD ]\}}	z||	}
W n  ty   tjg td}
Y n0 |du r| j| }n|}| jrt|
}
t|j	
dr|f |
|	|d| qj||
f|	|d| qjq|   | S )z<Put marginal plot on each diagonal axes, iterating over hue.r   Nr   r!   )dtype)r	  rt   r   )rt   r   )r   r   rX  rY  r   groupbyr]  r0   r   r5   r   r   r  r   ra  	get_groupKeyErrorr[  r\  floatr   r   r   	remove_narZ  )r   r*   r    Zfixed_colorrw  r!   hue_groupedr  r   label_kdata_kr   r"   r"   r#   rt    s,    


zPairGrid._map_diag_iter_huec                 K  s   ddl m}m} ||u s ||u r&d| _| }|D ]L\}}| j| }	| j| }
| j||f }|du rfq2| j|	|
||fi | q2| 	  dt
|jv rt| j| _dS )z,Draw a bivariate plot on the indicated axes.r   histplotkdeplotTNr   )distributionsr  r  r<   r0   rK  rL  r   _plot_bivariaterZ  r   rs  rV   rT   rU   )r   r*   rd  r    r  r  kwsr   r   r  r  r!   r"   r"   r#   re    s    

zPairGrid._map_bivariatec                 K  s  dt |jvr*| j||||fi | dS | }t|jdrL||d< n
t| ||krf|g}n||g}| j	dur| j	|vr|
| j	 | j| }| jr| }|| }|| }	| j	du rd}
n|| j	}
d|vr||
| j| jd |f ||	d| | | dS )z,Draw a bivariate plot on the specified axes.r   Nr   r!   )r   r   r   r	  r
  )r   rs  _plot_bivariate_iter_huer0   r   r5   r   r   r  r]   ra   r   r   r   rC   r   ra  r`  r   )r   r  r  r!   r*   r    	axes_varsr   r	  r
  r   r"   r"   r#   r  &  s4    




zPairGrid._plot_bivariatec              	   K  sN  |  }t|jdr"||d< n
t| ||kr<|g}n||g}| j| j}t	| j
D ]\}}	|  }
z||	}W n  ty   tj|td}Y n0 | jr||  }|| }|| }| j D ]\}}|| |
|< q|
d| j|  | jdur|	|
d< t|jdr,|f ||d|
 q\|||fi |
 q\| | dS )z7Draw a bivariate plot while iterating over hue subsets.r   r!   )columnsrz  r   Nrt   r  )r0   r   r5   r   r   r  r   r{  r]  r   ra  r|  r}  r[  	DataFramer~  r   r   r   r   r1   r   r]   r   )r   r  r  r!   r*   r    r  r  r   r  r  r  r	  r
  r  r  r"   r"   r#   r  M  s:    

z!PairGrid._plot_bivariate_iter_huec                 C  s`   t | jdddf | jD ]\}}|| qt | jdddf | jD ]\}}|| qHdS )z'Add labels to the left and bottom Axes.r)  Nr   )r   r   rK  r  rL  r  )r   r!   rt   r"   r"   r#   rZ  y  s    ""zPairGrid._add_axis_labelsc                 C  s,   g }|D ]}t || dkr|| q|S )z0Find which variables in a DataFrame are numeric.numeric)r   ra   )r   r   rc  r   r"   r"   r#   rS    s
    zPairGrid._find_numeric_cols)r4   r5   r6   r7   r=   rX   rj  rk  rl  ry  rt  re  r  r  rZ  rS  rH  r"   r"   r   r#   r     s"   

 /R'',r   c                   @  sz   e Zd ZdZddddddddddddddddd	Zd
d Zdd Zdd Zdd ZdddddddddZ	dddZ
dS )r   zGrid for drawing a bivariate plot with marginal univariate plots.

    Many plots can be drawn by using the figure-level interface :func:`jointplot`.
    Use this class directly when you need more flexibility.

    N      皙?F)r	  r
  r   r   ratiospacer   r   hue_normr   r   r   marginal_ticksc                  s  t j||fd}t |d |d }||dd d df }|j|dd df |d}|j|dd df |d}|| _|| _|| _|| _t j|	 dd t j|
 dd t j|j	d	d
dd t j|j
d	d
dd |st j|j dd t j|j dd t j|j dd t j|j dd t j|
 dd t j|	 dd t j|j
d	d
dd t j|j	d	d
dd |jd |jd t|t|||dd  jjd d  j  f |rڈ  fdd}|d| _|d| _|d| _dD ]4} j|d }|d ur
t|d| d| q
|d urT|| |d urh|| t||	|
d| _t !| |st j!|d	d t j!|d	d ||fD ]&}|j|jfD ]}|j"#d qq|$  |j%||d d S )Nr   r   r)  r   )r   )r   F)visibleT)minor)r	  r
  r   )r   	variablesc                   s,    | d }|d ur(| j | d }|S r  )rC   renamer  )rw  rx  pr  r"   r#   get_var  s    z#JointGrid.__init__.<locals>.get_varr	  r
  r   r.  set_rt   )r   r   r  rm  )r!   bottom)hspacewspace)&r   r(   GridSpecr   r%   ax_joint	ax_marg_x	ax_marg_ysetpr   r   r   get_majorticklinesget_minorticklinesr   gridr   r   r  rM   ru  anyr   r	  r
  r   r  rC   r   set_xlimset_ylim_hue_paramsr   r   rt   r   r@   rl   )r   r   r	  r
  r   r   r  r  r   r   r  r   r   r   r  fgsr  r  r  r  r   namer   r"   r  r#   r=     sd    	








zJointGrid.__init__c                 C  s4   t |j}| D ]\}}||v r||| qdS )z/Add params to kws if they are accepted by func.N)r   rs  r   r1   )r   r*   r  r   func_paramsr  r  r"   r"   r#   _inject_kwargs  s    
zJointGrid._inject_kwargsc                 K  s(   | j |fi | | j|fi | | S )a  Draw the plot by passing functions for joint and marginal axes.

        This method passes the ``kwargs`` dictionary to both functions. If you
        need more control, call :meth:`JointGrid.plot_joint` and
        :meth:`JointGrid.plot_marginals` directly with specific parameters.

        Parameters
        ----------
        joint_func, marginal_func : callables
            Functions to draw the bivariate and univariate plots. See methods
            referenced above for information about the required characteristics
            of these functions.
        kwargs
            Additional keyword arguments are passed to both functions.

        Returns
        -------
        :class:`JointGrid` instance
            Returns ``self`` for easy method chaining.

        )plot_marginals
plot_joint)r   Z
joint_funcZmarginal_funcr    r"   r"   r#   plot  s    zJointGrid.plotc                 K  s   |  }t|jdr$| j|d< nt| j | jdurT| j|d< | ||| j	 t|jdr~|f | j
| jd| n|| j
| jfi | | S )a  Draw a bivariate plot on the joint axes of the grid.

        Parameters
        ----------
        func : plotting callable
            If a seaborn function, it should accept ``x`` and ``y``. Otherwise,
            it must accept ``x`` and ``y`` vectors of data as the first two
            positional arguments, and it must plot on the "current" axes.
            If ``hue`` was defined in the class constructor, the function must
            accept ``hue`` as a parameter.
        kwargs
            Keyword argument are passed to the plotting function.

        Returns
        -------
        :class:`JointGrid` instance
            Returns ``self`` for easy method chaining.

        r   r!   Nr   r  )r0   r   r5   r   r  r   r  r   r  r  r	  r
  )r   r*   r    r"   r"   r#   r    s    

zJointGrid.plot_jointc                 K  s@  t |jdo|jdk }t|j}| }| jdurR| j|d< | ||| j	 d|v rf|
dd d|v rddi}dd	i}nd|v rddi}dd
i}|r|f | j| jd| n"t| j || jfi || |r|f | j| jd| n"t| j || jfi || | jj d | jj d | S )a  Draw univariate plots on each marginal axes.

        Parameters
        ----------
        func : plotting callable
            If a seaborn function, it should  accept ``x`` and ``y`` and plot
            when only one of them is defined. Otherwise, it must accept a vector
            of data as the first positional argument and determine its orientation
            using the ``vertical`` parameter, and it must plot on the "current" axes.
            If ``hue`` was defined in the class constructor, it must accept ``hue``
            as a parameter.
        kwargs
            Keyword argument are passed to the plotting function.

        Returns
        -------
        :class:`JointGrid` instance
            Returns ``self`` for easy method chaining.

        r   ZdistplotNr   rc   Forientationvertical
horizontalT)r	  r!   )r
  r!   )r   r5   r   r4   r   rs  r0   r   r  r  r1   r	  r  r   r  r
  r  r   	get_labelr   r   )r   r*   r    Zseaborn_funcr  Zorient_kw_xZorient_kw_yr"   r"   r#   r  (  s6    




zJointGrid.plot_marginalsTr9  r:  )r	  r
  jointmarginalr   r;  c                K  s   ||d< ||d< |durH|r0| j j|fi | |rH| jj|fi | |dur|rh| j j|fi | |r| jj|fi | | S )aJ  Add a reference line(s) to joint and/or marginal axes.

        Parameters
        ----------
        x, y : numeric
            Value(s) to draw the line(s) at.
        joint, marginal : bools
            Whether to add the reference line(s) to the joint/marginal axes.
        color : :mod:`matplotlib color <matplotlib.colors>`
            Specifies the color of the reference line(s).
        linestyle : str
            Specifies the style of the reference line(s).
        line_kws : key, value mappings
            Other keyword arguments are passed to :meth:`matplotlib.axes.Axes.axvline`
            when ``x`` is not None and :meth:`matplotlib.axes.Axes.axhline` when ``y``
            is not None.

        Returns
        -------
        :class:`JointGrid` instance
            Returns ``self`` for easy method chaining.

        r   r;  N)r  r<  r  r=  r  )r   r	  r
  r  r  r   r;  r>  r"   r"   r#   r?  e  s    zJointGrid.refliner   c                 K  s,   | j j|fi | | j j|fi | | S )a  Set 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 following functions:

            - :meth:`matplotlib.axes.Axes.set_xlabel`
            - :meth:`matplotlib.axes.Axes.set_ylabel`

        Returns
        -------
        :class:`JointGrid` instance
            Returns ``self`` for easy method chaining.

        )r  r  r  )r   xlabelylabelr    r"   r"   r#   r    s    zJointGrid.set_axis_labels)N)r   r   )r4   r5   r6   r7   r=   r  r  r  r  r?  r  r"   r"   r"   r#   r     s     R$>,r   a  Set up the grid of subplots and store data internally for easy plotting.

Parameters
----------
{params.core.data}
{params.core.xy}
height : number
    Size of each side of the figure in inches (it will be square).
ratio : number
    Ratio of joint axes height to marginal axes height.
space : number
    Space between the joint and marginal axes
dropna : bool
    If True, remove missing observations before plotting.
{{x, y}}lim : pairs of numbers
    Set axis limits to these values before plotting.
marginal_ticks : bool
    If False, suppress ticks on the count/density axis of the marginal plots.
{params.core.hue}
    Note: unlike in :class:`FacetGrid` or :class:`PairGrid`, the axes-level
    functions must support ``hue`` to use it in :class:`JointGrid`.
{params.core.palette}
{params.core.hue_order}
{params.core.hue_norm}

See Also
--------
{seealso.jointplot}
{seealso.pairgrid}
{seealso.pairplot}

Examples
--------

.. include:: ../docstrings/JointGrid.rst

returnsseealso)r   r  r  scatterautorI  F)r   r   r   rJ  rK  rL  kind	diag_kindmarkersr   r   rM  r   plot_kwsdiag_kwsgrid_kwsrN   c                C  s  ddl m}m} |dur,|}
d}t|t t| tjsJt	dt
|  |du rVi n| }|du rji n| }|du r~i n| }|dkr|du r|dkrdnd}n|dkrdnd}|d	|dk t| f||||||||
||d

|}|	dur|dkrV|jdu rd}n
t|j}t|	ts4|	g| }	t|	|krJtdd|	i|_n>|dkrt|	trv|	|d< n|dur| | |d< |	|d< | }|dd |dkr|j|fi | n4|dkr|dd |dd |j|fi | |dur|j}n|j}|dkr:ddlm} ||fi | n|dkrbddlm} ||fi | nZ|dkrddl m} |dd ||fi | n&|dkrddl m} ||fi | |dur|  |  |S )aY  Plot pairwise relationships in a dataset.

    By default, this function will create a grid of Axes such that each numeric
    variable in ``data`` will by shared across the y-axes across a single row and
    the x-axes across a single column. The diagonal plots are treated
    differently: a univariate distribution plot is drawn to show the marginal
    distribution of the data in each 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 : `pandas.DataFrame`
        Tidy (long-form) dataframe where each column is a variable and
        each row is an observation.
    hue : name of variable in ``data``
        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
        Variables within ``data`` to use, otherwise use every column with
        a numeric datatype.
    {x, y}_vars : lists of variable names
        Variables within ``data`` to use separately for the rows and
        columns of the figure; i.e. to make a non-square plot.
    kind : {'scatter', 'kde', 'hist', 'reg'}
        Kind of plot to make.
    diag_kind : {'auto', 'hist', 'kde', None}
        Kind of plot for the diagonal subplots. If 'auto', choose based on
        whether or not ``hue`` is used.
    markers : single matplotlib marker code or list
        Either the marker to use for all scatterplot points 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
        Height (in inches) of each facet.
    aspect : scalar
        Aspect * height gives the width (in inches) of each facet.
    corner : bool
        If True, don't add axes to the upper (off-diagonal) triangle of the
        grid, making this a "corner" plot.
    dropna : boolean
        Drop missing values from the data before plotting.
    {plot, diag, grid}_kws : dicts
        Dictionaries of keyword arguments. ``plot_kws`` are passed to the
        bivariate plotting function, ``diag_kws`` are passed to the univariate
        plotting function, and ``grid_kws`` are passed to the :class:`PairGrid`
        constructor.

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

    See Also
    --------
    PairGrid : Subplot grid for more flexible plotting of pairwise relationships.
    JointGrid : Grid for plotting joint and marginal distributions of two variables.

    Examples
    --------

    .. include:: ../docstrings/pairplot.rst

    r   r  NzKThe `size` parameter has been renamed to `height`; please update your code.z-'data' must be pandas DataFrame object, not: r  kdehistrN  )
rJ  rK  rL  r   r   r   rM  r   r   r   regzSmarkers must be a singleton or a list of markers for each level of the hue variablemarkerr  r  r  rc   FfillTwarn_singularscatterplot)regplot)r  )r  )r  r  r  r   r   UserWarningr_   r[  r  	TypeErrortyper0   r1   r   rU   r   rV   r   r   r   ry  rl  rX   
relationalr  
regressionr  ry   r@   )r   r   r   r   rJ  rK  rL  r  r  r  r   r   rM  r   r  r  r  rN   r  r  msgr  Z	n_markersplotterr  r  r"   r"   r#   r     s    S














r   r  r  r  )r	  r
  r   r  r   r  r  r   r   r   r   r   r   r  r  	joint_kwsmarginal_kwsc          *        s  ddl m} ddlm}m} ddlm}m}m} |	dd d urTd}t
j|tdd |d u r`i n| }|| |d u r~i n| }g d	}g }|D ] }||v r|| |	| q|r|d
krdd|}t
|t g d}td|| |d ur|dv rd| d}t||d u r*d}tjj|  fddtdddD }t|dd}|dkrnd}t| |||||||||||	|
|d} | jd ur|dd |dr$|d| | j|fi | | jd u r|}!n|}!|dd |d d |d| | j |!fi | n|d!r |d| | j|fi | |d
d |d| | }"| }#d"}$|$D ]<}t!|"|t#r~|| \}%}&|"||% |#||& q~|f | ||d#|"d| j$i |f | ||d$|#d| j%i n|d
rr|d| |dd | j|fi | |d| d |v r\|d |d   | j |fi | nh|drt&|| j'd%}'t&|| j(d%}(t)t*|'|(g})|d&|) |d'| | jt+j,fi | |d
d |d| | j |fi | n|d(r^|d| |d
d | j |fi | |d| | j|fi | n||d)r|d| | j|fi | | j-j.d / j0\}}|d| |f ||| j$d*| |f ||| j%d+| t+1| j- | S ),Nr   r  )r  	residplot)r  r  _freedman_diaconis_binsr!   z4Ignoring `ax`; jointplot is a figure-level function.rR   )
stacklevel)ZrugfitZhist_kwsZnorm_histhist_kwsZrug_kwsr  znThe marginal plotting function has changed to `histplot`, which does not accept the following argument(s): {}.z, )r  r  hexr  r  residr  )r  r  r  zUse of `hue` with `kind='z'` is not currently supported.C0c                   s   g | ]}t j |d qS ))rF   )r   set_hls_valuesrD   Z	color_rgbr"   r#   rI     s   zjointplot.<locals>.<listcomp>r      T)as_cmapr  )r   r	  r
  r   r   r   r  r   r   r  r  r   r   r  rc   Fr  r   r  r  r  )binsbinwidthbinrange)r   r	  r   )r   r
  r   2   gridsizecmapr  r  )r	  r   r!   )r
  r   r!   )2r  r  r  r  r  r  r  r  r  r   r   r   r  r0   r   ra   r   r4  r   r   rZ   r   colorConverterto_rgbr   linspacer   r   r   r1   r   r  r  r_   rC   r`   r  r  minr	  r
  r   meanr   hexbinr  collectionsget_offsetsTr  )*r   r	  r
  r   r  r   r  r  r   r   r   r   r   r   r  r  r  r  r    r  r  r  r  r  r  r  Zdistplot_keysZunused_keysr  Z
plot_kindsr   r  r  Z	marg_funcZ
marg_x_kwsZ
marg_y_kwsZ	pair_keysZx_valZy_valZx_binsZy_binsr  r"   r  r#   r     s    





 $
r   a4  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
----------
{params.core.data}
{params.core.xy}
{params.core.hue}
    Semantic variable that is mapped to determine the color of plot elements.
kind : {{ "scatter" | "kde" | "hist" | "hex" | "reg" | "resid" }}
    Kind of plot to draw. See the examples for references to the underlying functions.
height : numeric
    Size of the figure (it will be square).
ratio : numeric
    Ratio of joint axes height to marginal axes height.
space : numeric
    Space between the joint and marginal axes
dropna : bool
    If True, remove observations that are missing from ``x`` and ``y``.
{{x, y}}lim : pairs of numbers
    Axis limits to set before plotting.
{params.core.color}
{params.core.palette}
{params.core.hue_order}
{params.core.hue_norm}
marginal_ticks : bool
    If False, suppress ticks on the count/density axis of the marginal plots.
{{joint, marginal}}_kws : dicts
    Additional keyword arguments for the plot components.
kwargs
    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
-------
{returns.jointgrid}

See Also
--------
{seealso.jointgrid}
{seealso.pairgrid}
{seealso.pairplot}

Examples
--------

.. include:: ../docstrings/jointplot.rst

)N)3
__future__r   	itertoolsr   inspectr   r   textwrapr   numpyr   pandasr[  r   rZ   matplotlib.pyplotpyplotr   _oldcorer   r   r	   _compatr
   r   r   r   r   r   r   palettesr   r   _docstringsr   r   __all__from_nested_components_param_docsr   r9   r   rG  r   r   r   r   r=   r7   r   r   r"   r"   r"   r#   <module>   s   B O;      /   x  "&
. 0 
 $7