a
    Sic>n                     @   s  d Z ddlZddl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
 ddlZddlZddlZddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ g d
Zdd Zdd Zdd Zdd Z dd Z!dd Z"dFddZ#dd Z$dd Z%dd Z&dGd!d"Z'd#d$ Z(d%d& Z)dHd(d)Z*d*d+ Z+dId,d-Z,dJd.d/Z-d0d1 Z.d2d3 Z/d4d5 Z0d6d7 Z1d8d9 Z2d:d; Z3d<d= Z4d>d? Z5d@dA Z6dBdC Z7edDdE Z8dS )Kz+Utility functions, mostly for internal use.    N)contextmanager)urlopenurlretrieve)to_rgb)normalize_kwargs   )Version)user_cache_dir)
desaturatesaturateset_hls_valuesmove_legenddespineget_dataset_namesget_data_homeload_datasetc           	      C   sr   t | dd} t |}g }tt | D ]2\}\}}|| }|| }|| }|||g q.t |j}|S )a  Convert intervals to error arguments relative to plot heights.

    Parameters
    ----------
    cis : 2 x n sequence
        sequence of confidence interval limits
    heights : n sequence
        sequence of plot heights

    Returns
    -------
    errsize : 2 x n array
        sequence of error size relative to height values in correct
        format as argument for plt.bar

       )	np
atleast_2dreshape
atleast_1d	enumerate	transposeappendasarrayT)	ZcisheightsZerrsizeilowhighhZelowZehigh r"   I/var/www/html/django/DPS/env/lib/python3.9/site-packages/seaborn/utils.pyci_to_errsize   s    
r$   c                 C   sp   zddl m} t| j}W nH tyf   zddlm} |j}W n ty`   d}t	|Y n0 Y n0 || S )z
    Compute the quantile function of the standard normal distribution.

    This wrapper exists because we are dropping scipy as a mandatory dependency
    but statistics.NormalDist was added to the standard library in 3.8.

    r   )
NormalDist)normzFStandard normal quantile functions require either Python>=3.8 or scipy)

statisticsr%   r   	vectorizeZinv_cdfImportErrorscipy.statsr&   ZppfRuntimeError)qr%   Zqfr&   msgr"   r"   r#   _normal_quantile_func6   s    
r.   c                 C   s<   | j   | jr8z| | j   W n ty6   Y n0 dS )z>Force draw of a matplotlib figure, accounting for back-compat.N)canvasdrawstaleget_rendererAttributeError)figr"   r"   r#   _draw_figureM   s    
r5   c                    s  |durdS |dur|S | j dkr^t tjjd}| g g dd|d\}| }|  nf| j dkrt fddd	D }t	
|t	j }}| ||fi  }| }t|sd}	nt	j|d
djd
 dk}	d vr|	rt|d
 }|  n| j dkr0| t	jgt	jgfi  \}t| }|  n| j dkr| j}
tt|
jjtjjt|
jjtjjg}ttjtdk r|rdS t tjj | g g fi  }| }t|d
 }|  |S )zFIf needed, get a default color by using the matplotlib property cycle.NplotcolorF)scalexscaleyr7   scatterc                 3   s&   | ]}t  |g jd  V  qdS )r   N)r   r   getshape).0keykwsr"   r#   	<genexpr>p   s   z!_default_color.<locals>.<genexpr>)scfc	facecolor
facecolorsr   )axisr   rC   barfill_betweenz3.3C0)__name___normalize_kwargsmpllinesLine2Dr;   	get_colorremovemaxr   fullnanget_facecolorslenuniquer<   r   get_facecolor__self__any
isinstancexaxis	converterdatesDateConverteryaxisr   __version__collectionsPolyCollection)methodhuer7   r@   ZscoutZ
scout_sizeZscout_xZscout_yrF   Zsingle_coloraxZdatetime_axisrE   r"   r?   r#   _default_colorX   sP    



rg   c                 C   sP   d|  krdksn t dt| }tj| \}}}||9 }t|||}|S )al  Decrease the saturation channel of a color by some percent.

    Parameters
    ----------
    color : matplotlib color
        hex, rgb-tuple, or html color name
    prop : float
        saturation channel of color will be multiplied by this value

    Returns
    -------
    new_color : rgb tuple
        desaturated color code in RGB tuple representation

    r   r   zprop must be between 0 and 1)
ValueErrorr   colorsys
rgb_to_hls
hls_to_rgb)r7   proprgbr!   lrB   	new_colorr"   r"   r#   r
      s    r
   c                 C   s   t | ddS )a
  Return a fully saturated color with the same hue.

    Parameters
    ----------
    color : matplotlib color
        hex, rgb-tuple, or html color name

    Returns
    -------
    new_color : rgb tuple
        saturated color code in RGB tuple representation

    r   )rB   )r   )r7   r"   r"   r#   r      s    r   c                 C   sL   t | }ttj| }t|||gD ]\}}|dur$|||< q$tj| }|S )an  Independently manipulate the h, l, or s channels of a color.

    Parameters
    ----------
    color : matplotlib color
        hex, rgb-tuple, or html color name
    h, l, s : floats between 0 and 1, or None
        new values for each channel in hls space

    Returns
    -------
    new_color : rgb tuple
        new color code in RGB tuple representation

    N)r   listri   rj   r   rk   )r7   r!   rn   rB   rm   valsr   valr"   r"   r#   r      s    

r   c                 K   s@   d}t |t t }|j| fi | |j|fi | dS )z[Grab current axis and label it.

    DEPRECATED: will be removed in a future version.

    zCThis function is deprecated and will be removed in a future versionN)warningswarnFutureWarningpltgca
set_xlabel
set_ylabel)xlabelylabelkwargsr-   rf   r"   r"   r#   axlabel   s
    r}   c                 C   s   | t |  S )aG  Helper method for removing null values from data vectors.

    Parameters
    ----------
    vector : vector object
        Must implement boolean masking with [] subscript syntax.

    Returns
    -------
    clean_clean : same type as ``vector``
        Vector of data with null values removed. May be a copy or a view.

    )pdnotnull)vectorr"   r"   r#   	remove_na  s    r   c                  C   s&   t jd } d| jv r |  d S dgS )a	  Return the list of colors in the current matplotlib color cycle

    Parameters
    ----------
    None

    Returns
    -------
    colors : list
        List of matplotlib colors in the current cycle, or dark gray if
        the current color cycle is empty.
    zaxes.prop_cycler7   z.15)rM   rcParamskeysby_key)cyclerr"   r"   r#   get_color_cycle  s    
r   TFc              
   C   s  | du r|du rt  j}n| dur,| j}n|dur:|g}|D ]}	dD ]h}
t |
  }|	j|
 | |durH|rHz||
d}W n ty   |}Y n0 |	j|
 d|f qH|r,|s,t	dd |	j
jD }t	dd |	j
jD }|	j
d |	j
jD ]}|j| q|	j
jD ]}|j| q|r|st	d	d |	jjD }t	d
d |	jjD }|	jd |	jjD ]}|j| qx|	jjD ]}|j| q|r>t|	 }|jrDt|t|	 k|d }t|t|	 k|d }|	jd || |	jd || |||k}|||k}|	| t|	 }|jr>t|t|	 k|d }t|t|	 k|d }|	jd || |	jd || |||k}|||k}|	| q>dS )a  Remove the top and right spines from plot(s).

    fig : matplotlib figure, optional
        Figure to despine all axes of, defaults to the current figure.
    ax : matplotlib axes, optional
        Specific axes object to despine. Ignored if fig is provided.
    top, right, left, bottom : boolean, optional
        If True, remove that spine.
    offset : int or dict, optional
        Absolute distance, in points, spines should be moved away
        from the axes (negative values move spines inward). A single value
        applies to all spines; a dict can be used to set offset values per
        side.
    trim : bool, optional
        If True, limit spines to the smallest and largest major tick
        on each non-despined axis.

    Returns
    -------
    None

    N)toprightleftbottomr   outwardc                 s   s   | ]}|j  V  qd S N	tick1lineget_visibler=   tr"   r"   r#   rA   T  s   zdespine.<locals>.<genexpr>c                 s   s   | ]}|j  V  qd S r   r   r   r"   r"   r#   rA   X  s   r   c                 s   s   | ]}|j  V  qd S r   r   r   r"   r"   r#   rA   c  s   c                 s   s   | ]}|j  V  qd S r   r   r   r"   r"   r#   rA   g  s   r   r   r   r   )rv   gcfaxeslocalsspinesset_visibler;   r3   set_positionrZ   r`   
majorTicks
minorTicksset_ticks_position	tick2liner\   r   r   
get_xtickssizecompressminget_xlimrR   
set_bounds
set_xticks
get_yticksget_ylim
set_yticks)r4   rf   r   r   r   r   offsettrimr   Zax_isideZ
is_visiblerr   Zmaj_onZmin_onr   xticksZ	firsttickZlasttickZnewticksyticksr"   r"   r#   r   &  s    


r   c                    s  ddl m} t| |r&| j}| jj}nTt| tjjrB| j}| j}n8t| tjj	rn| j
rb| j
d }nd}| j}nd}t||du r|  d}t||j}dd | D }ttjjj  fd	d
|  D }	|	d |	d}
d|v r|
|d dd
 | D }| D ]0\}}|
jf i |dd |i || q|d|j  |	| |  |||fd|i|	}||
 |
  t| |r|| _ dS )a<  
    Recreate a plot's legend at a new location.

    The name is a slight misnomer. Matplotlib legends do not expose public
    control over their position parameters. So this function creates a new legend,
    copying over the data from the original object, which is then removed.

    Parameters
    ----------
    obj : the object with the plot
        This argument can be either a seaborn or matplotlib object:

        - :class:`seaborn.FacetGrid` or :class:`seaborn.PairGrid`
        - :class:`matplotlib.axes.Axes` or :class:`matplotlib.figure.Figure`

    loc : str or int
        Location argument, as in :meth:`matplotlib.axes.Axes.legend`.

    kwargs
        Other keyword arguments are passed to :meth:`matplotlib.axes.Axes.legend`.

    Examples
    --------

    .. include:: ../docstrings/move_legend.rst

    r   )Gridr   NzC`obj` must be a seaborn Grid or matplotlib Axes or Figure instance.z has no legend attached.c                 S   s   g | ]}|  qS r"   )get_textr   r"   r"   r#   
<listcomp>      zmove_legend.<locals>.<listcomp>c                    s   i | ]\}}| v r||qS r"   r"   r=   kvZ
legend_kwsr"   r#   
<dictcomp>  r   zmove_legend.<locals>.<dictcomp>bbox_to_anchortitlec                 S   s    i | ]\}}| d r||qS )Ztitle_)
startswithr   r"   r"   r#   r     r      frameonloc)!Zseaborn.axisgridr   r[   legendfigurerM   r   Axeslegend_Figurelegends	TypeErrorrh   legendHandles	get_textsinspect	signatureLegend
parameters
propertiesitemspopset_textset
setdefaultlegendPatchr   updaterQ   	set_titler   get_fontproperties_legend)objr   r|   r   Z
old_legendZlegend_funcerrhandleslabelspropsr   Ztitle_kwargsr>   rr   Z
new_legendr"   r   r#   r     sH     






r   c                 C   sF   t |  ||  |d }t|   ||  |d }t|||}|S )z0Establish support for a kernel density estimate.r   r   )rR   r   r   linspace)databwgridsizecutclipZsupport_minZsupport_maxsupportr"   r"   r#   _kde_support  s    r   _   c                 C   s&   d|d  d|d  f}t | ||S )z2Return a percentile range from an array of values.2   r   )r   nanpercentile)awhichrG   pr"   r"   r#   ci  s    r   c                  C   sL   d} t | }| }W d   n1 s*0    Y  d}t|| }|S )zkReport available example datasets, useful for reporting issues.

    Requires an internet connection.

    z'https://github.com/mwaskom/seaborn-dataNz+/mwaskom/seaborn-data/blob/master/(\w*).csv)r   readrefindalldecode)urlresphtmlpatdatasetsr"   r"   r#   r     s    
&r   c                 C   s@   | du rt jdtd} t j| } t j| s<t |  | S )aL  Return a path to the cache directory for example datasets.

    This directory is used by :func:`load_dataset`.

    If the ``data_home`` argument is not provided, it will use a directory
    specified by the `SEABORN_DATA` environment variable (if it exists)
    or otherwise default to an OS-appropriate user cache location.

    NZSEABORN_DATAseaborn)osenvironr;   r	   path
expanduserexistsmakedirs)	data_homer"   r"   r#   r     s    

r   c           
      K   s  t | tjrd}t|d|  d}|rxtjt|tj|}tj	|sr| t
 vrhtd|  dt|| |}n|}tj|fi |}|jd   r|jdd }| dkrt|d	 g d
|d	< t|d ddg|d< t|d ddg|d< t|d ddg|d< n| dkrP|d jdd }	t|	|	 |d< nn| dkrt|d g d|d< t|d g d|d< t|d ddg|d< n| dkrt|d g d |d< t|d! td"|d!< n| d#kr |d j |d< n| d$krTt|d% g d&|d%< t|d' g d(|d'< t|d) g d*|d)< nj| d+krt|d, |d,< t|d- |d-< n:| d.krt|d/ |d/< n| d0krt|d/ |d/< |S )1a  Load an example dataset from the online repository (requires internet).

    This function provides quick access to a small number of example datasets
    that are useful for documenting seaborn or generating reproducible examples
    for bug reports. It is not necessary for normal usage.

    Note that some of the datasets have a small amount of preprocessing applied
    to define a proper ordering for categorical variables.

    Use :func:`get_dataset_names` to see a list of available datasets.

    Parameters
    ----------
    name : str
        Name of the dataset (``{name}.csv`` on
        https://github.com/mwaskom/seaborn-data).
    cache : boolean, optional
        If True, try to load from the local cache first, and save to the cache
        if a download is required.
    data_home : string, optional
        The directory in which to cache data; see :func:`get_data_home`.
    kws : keys and values, optional
        Additional keyword arguments are passed to passed through to
        :func:`pandas.read_csv`.

    Returns
    -------
    df : :class:`pandas.DataFrame`
        Tabular data, possibly with some preprocessing applied.

    zThis function accepts only strings (the name of an example dataset). You passed a pandas DataFrame. If you have your own dataset, it is not necessary to use this function before plotting.z>https://raw.githubusercontent.com/mwaskom/seaborn-data/master/z.csv'z%' is not one of the example datasets.r   NZtipsday)ZThurFriSatSunZsexZMaleZFemaletimeZLunchZDinnerZsmokerYesNoflightsmonth   exercise)z1 minz15 minz30 minkind)restZwalkingrunningZdietzno fatzlow fatZtitanicclass)ZFirstSecondZThirdZdeckZABCDEFGZpenguinsZdiamondsr7   )DEFGHIJZclarity)IFZVVS1ZVVS2ZVS1ZVS2ZSI1ZSI2ZI1r   )ZIdealZPremiumz	Very GoodZGoodZFairZtaxispickupZdropoffZseaiceDateZdowjones)r[   r~   	DataFramer   r   r   joinr   basenamer   r   rh   r   read_csvilocisnullallCategoricalstrrW   rp   r   to_datetime)
namecacher   r@   r   r   
cache_path	full_pathdfmonthsr"   r"   r#   r     sf    #











r   c                    sP   | sdS z.dd | D   fdd D }t |dkW S  tyJ   Y dS 0 dS )zReturn a boolean for whether the list of ticklabels have overlaps.

    Parameters
    ----------
    labels : list of matplotlib ticklabels

    Returns
    -------
    overlap : boolean
        True if any of the labels overlap.

    Fc                 S   s   g | ]}|  qS r"   )get_window_extentr=   rn   r"   r"   r#   r     r   z+axis_ticklabels_overlap.<locals>.<listcomp>c                    s   g | ]}|  qS r"   )count_overlaps)r=   bbboxesr"   r#   r     r   r   N)rR   r+   )r   overlapsr"   r&  r#   axis_ticklabels_overlap  s    r)  c                 C   s   t |  t |  fS )zReturn booleans for whether the x and y ticklabels on an Axes overlap.

    Parameters
    ----------
    ax : matplotlib Axes

    Returns
    -------
    x_overlap, y_overlap : booleans
        True when the labels on that axis overlap.

    )r)  get_xticklabelsget_yticklabels)rf   r"   r"   r#   axes_ticklabels_overlap  s    

r,  c                    s   | j  |}fdd|D }G fddd}t| tjjrNtj  n
tj  |  _ 	|  fdd|D }||fS )z=Return levels and formatted levels for brief numeric legends.c                    s(   g | ] }| d  kr| d kr|qS )r   r   r"   r#  limitsr"   r#   r     r   z-locator_to_legend_entries.<locals>.<listcomp>c                       s   e Zd Z fddZdS )z-locator_to_legend_entries.<locals>.dummy_axisc                    s    S r   r"   )selfr-  r"   r#   get_view_interval  s    z?locator_to_legend_entries.<locals>.dummy_axis.get_view_intervalN)rK   
__module____qualname__r0  r"   r-  r"   r#   
dummy_axis  s   r3  c                    s   g | ]} |qS r"   r"   )r=   x)	formatterr"   r#   r     r   )
tick_valuesastyper[   rM   ticker
LogLocatorLogFormatterScalarFormatterrG   set_locs)locatorr.  dtypeZ
raw_levelsr3  Zformatted_levelsr"   )r5  r.  r#   locator_to_legend_entries  s    

r?  c                 C   st   t jj| ddddf }t|dk|d |d d d }|g d}z
| W S  tyn   | Y S 0 dS )	a  Calculate the relative luminance of a color according to W3C standards

    Parameters
    ----------
    color : matplotlib color or sequence of matplotlib colors
        Hex code, rgb-tuple, or html color name.

    Returns
    -------
    luminance : float(s) between 0 and 1

    Nr  g#?gףp=
)@g)\(?gzG?g333333@)gz6?g,C?g]m{?)	rM   colorscolorConverterto_rgba_arrayr   wheredotitemrh   )r7   rm   Zlumr"   r"   r#   relative_luminance  s    "
rF  c                 C   s<   t | tr| S z| jddW S  ty6   t|  Y S 0 dS )a  Return a string representing a Python object.

    Strings (i.e. type ``str``) are returned unchanged.

    Byte strings (i.e. type ``bytes``) are returned as UTF-8-decoded strings.

    For other objects, the method ``__str__()`` is called, and the result is
    returned as a string.

    Parameters
    ----------
    obj : object
        Any Python object

    Returns
    -------
    s : str
        UTF-8-decoded string representation of ``obj``

    zutf-8)encodingN)r[   r  r   r3   )r   r"   r"   r#   to_utf8  s    
rH  c              
   C   sZ   dgdgdgdgdgdgdgdgd	gd
	}zt | |} W n tyT   t | |} Y n0 | S )z>Wrapper for mpl.cbook.normalize_kwargs that supports <= 3.2.1.rC   lwlsrD   ecmfcmecmewms)	r7   	linewidth	linestylerE   	edgecolormarkerfacecolormarkeredgecolormarkeredgewidth
markersize)r   r3   )r@   artist
_alias_mapr"   r"   r#   rL     s    rL   c                 C   s,   ||vr(t d|  d| dt| ddS )z+Raise if value for param is not in options.`z` must be one of z, but z was passed.N)rh   repr)paramoptionsvaluer"   r"   r#   _check_argument  s    r^  c                 C   sD   t |j}t |j}|D ]"}||v r|| vr|| j| |< q| S )zBAssign default kwargs for call_func using values from source_func.)r   r   r   default)r@   Z	call_funcZsource_funcneededdefaultsr[  r"   r"   r#   _assign_default_kwargs  s    	rb  c                 C   s   t jdd}| tjjd  }|D ]T}| \}}| }tdd |D s(|	d | D ]}|durd|
| qdq(dS )z
    Make invisible-handle "subtitles" entries look more like titles.

    Note: This function is not part of the public API and may be changed or removed.

    zlegend.title_fontsizeNr   c                 s   s   | ]}|  V  qd S r   )r   )r=   rW  r"   r"   r#   rA   4  r   z*adjust_legend_subtitles.<locals>.<genexpr>)rv   r   r;   findobjrM   	offsetboxVPackerget_childrenr  	set_widthset_size)r   	font_sizeZhpackershpackZ	draw_area	text_arear   textr"   r"   r#   adjust_legend_subtitles'  s    
rm  c                 C   sP   |dkrL|du rd} n|dkr$d} nd|f} dt |  d}tj|tdd | S )	a  
    Warn on usage of ci= and convert to appropriate errorbar= arg.

    ci was deprecated when errorbar was added in 0.12. It should not be removed
    completely for some time, but it can be moved out of function definitions
    (and extracted from kwargs) after one cycle.

    
deprecatedNsdr   z2

The `ci` parameter is deprecated. Use `errorbar=z` for the same effect.
r  )
stacklevel)rZ  rs   rt   ru   )errorbarr   r-   r"   r"   r#   _deprecate_ci;  s    	rr  c               	   c   s:   t jd } zdt jd< dV  W | t jd< n| t jd< 0 dS )zBContext manager for preventing rc-controlled auto-layout behavior.zfigure.autolayoutFN)rM   r   )orig_valr"   r"   r#   _disable_autolayoutT  s
    

rt  )NNN)NNTTFFNF)r   N)N)TN)9__doc__r   r   r   rs   ri   
contextlibr   urllib.requestr   r   numpyr   pandasr~   
matplotlibrM   matplotlib.colorsr   matplotlib.pyplotpyplotrv   Zmatplotlib.cbookr   Zexternal.versionr   Zexternal.appdirsr	   __all__r$   r.   r5   rg   r
   r   r   r}   r   r   r   r   r   r   r   r   r   r)  r,  r?  rF  rH  rL   r^  rb  rm  rr  rt  r"   r"   r"   r#   <module>   s^   P#
  
fZ	


l