o
    i(                     @   sN  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m	Z	m
Z
 d dlm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 ddlmZmZ ddlmZmZmZ G dd dZeG dd deZ eG dd deZ!eG dd deZ"G dd dZ#G dd deZ$d%ddZ%d&ddZ&dd  Z'd!d" Z(d'd#d$Z)dS )(    Ncopy)partial)
UserString)IterableSequenceMapping)Number)datetime   )share_init_params_with_map)Version)QUAL_PALETTEScolor_palette)_check_argumentget_color_cycle	remove_nac                   @   sD   e Zd ZdZdZdZdZdd Zdd Zdd Z	d	d
 Z
dd ZdS )SemanticMappingz6Base class for mapping data values to plot attributes.Nc                 C   s
   || _ d S Nplotter)selfr    r   K/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/seaborn/_oldcore.py__init__+   s   
zSemanticMapping.__init__c                 O   s<   d| j d d   d}t||| |g|R i | |S )N_i_map)__name__lowersetattr)clsr   argskwargsmethod_namer   r   r   map4   s   zSemanticMapping.mapc                 C   s   d}t |t |kr/dd| dt | ddt | ddg}d	d
 t|t|D }n&t |t |krUdd| dt | ddt | dg}|dt | }|r_tj|tdd |S )z/Input check when values are provided as a list.  z
The z list has fewer values ()zthan needed (z) and will cycle, which mayz produce an uninterpretable plot.c                 S   s   g | ]\}}|qS r   r   ).0r   xr   r   r   
<listcomp>D       z6SemanticMapping._check_list_length.<locals>.<listcomp>The z list has more values (z), which may not be intended.N   
stacklevel)lenjoinzip	itertoolscyclewarningswarnUserWarning)r   levelsvaluesvariablemessager   r   r   _check_list_length:   s"   z"SemanticMapping._check_list_lengthc                 C   s
   | j | S )z)Apply the mapping to a single data value.lookup_table)r   keyr   r   r   _lookup_singleR   s   
zSemanticMapping._lookup_singlec                    sB   t |ttjtjfr fdd|D S j|g R i S )z-Get the attribute(s) values for the data key.c                    s$   g | ]}j |g R i qS r   )r@   r(   kr!   r"   r   r   r   r*   Y   s   $ z,SemanticMapping.__call__.<locals>.<listcomp>)
isinstancelistnpndarraypdSeriesr@   )r   r?   r!   r"   r   rC   r   __call__V   s   zSemanticMapping.__call__)r   
__module____qualname____doc__map_typer8   r>   r   r$   r<   r@   rJ   r   r   r   r   r      s    	r   c                       sP   e Zd ZdZdZdZdZ	d fdd	Zdd Zdd Z	d	d
 Z
dd Z  ZS )
HueMappingz9Mapping that sets artist colors according to data values.Nc                    s   t  | |jdtjtd}|  r(|dur&d}t	j
|dd dS dS | |||j|jd }|dkrIt|}| |||\}}	}}
n!|dkr[d }
}| |||\}}	nd }
}| t|||\}}	|| _|	| _|| _|| _|| _|
| _dS )	zMap the levels of the `hue` variable to distinct colors.

        Parameters
        ----------
        # TODO add generic parameters

        huedtypeNz?Ignoring `palette` because no `hue` variable has been assigned.   r.   numericcategorical)superr   	plot_datagetrH   rI   floatisnaallr5   r6   infer_map_typeinput_format	var_types
to_numericnumeric_mappingcategorical_mappingrE   rN   r>   paletter8   normcmap)r   r   rb   orderrc   datamsgrN   r8   r>   rd   	__class__r   r   r   j   s<   





zHueMapping.__init__c                 C   s   z| j | }W |S  tyN   | jdu rY dS z| |}W n ty< } zt|r.d}n|W Y d}~Y |S d}~ww tj|rFtj}| 	|}Y |S w )z@Get the color for a single value, using colormap to interpolate.N)r   r   r   r   )
r>   KeyErrorrc   	TypeErrorrF   isnanma	is_maskednanrd   )r   r?   valuenormederrr   r   r   r@      s*   

zHueMapping._lookup_singlec                 C   sN   |t v rd}|S |durd}|S t|ttfrd}|S |dkr#d}|S |}|S )z'Determine how to implement the mapping.rU   NrT   wide)r   rD   dictrE   )r   rb   rc   r]   var_typerN   r   r   r   r\      s   
zHueMapping.infer_map_typec           
      C   s   t ||}t|}t|tr)t|t| }t|r#d}t|||}||fS |du r@|tt kr:t	d|}	nt	d|}	nt|t
rM| ||d}	nt	||}	tt||	}||fS )z5Determine colors when the hue mapping is categorical.z*The palette dictionary is missing keys: {}Nhuslrb   )categorical_orderr0   rD   rt   setany
ValueErrorformatr   r   rE   r<   r2   )
r   rf   rb   re   r8   n_colorsmissingrr   r>   colorsr   r   r   ra      s$   



zHueMapping.categorical_mappingc           	         s
  t  tr!tt } fddt D }tj|}  }n^tt	t
| } du r2dn  t  tjjr> }nt dd}|du rNtj }nt |trZtjj| }nt |tjjsgd}t|| st|t|  tt||||}||||fS )z7Determine colors when the hue variable is quantitative.c                    s   g | ]} | qS r   r   rA   rb   r   r   r*      r+   z.HueMapping.numeric_mapping.<locals>.<listcomp>Nzch:T)as_cmapz6``hue_norm`` must be None, tuple, or Normalize object.)rD   rt   rE   sortedmplr~   ListedColormapr   rF   sortr   uniqueColormapr   	Normalizetuplerz   scaledasarraydropnar2   )	r   rf   rb   rc   r8   r~   rd   r>   rr   r   r   r   r`      s*   


zHueMapping.numeric_mappingNNN)r   rK   rL   rM   rb   rc   rd   r   r@   r\   ra   r`   __classcell__r   r   rh   r   rO   ^   s    @"rO   c                       sH   e Zd ZdZdZ	d fdd	Zdd Zdd Zd	d
 Zdd Z	  Z
S )SizeMappingz8Mapping that sets artist sizes according to data values.Nc           
         s   t  | |jdtjtd}|  rb| 	|||j
d }|dkr1| |||\}}}}	n|dkrA| |||\}}d}	n| t|||\}}d}	|| _|| _|| _|| _|	| _|| _dS dS )zMap the levels of the `size` variable to distinct values.

        Parameters
        ----------
        # TODO add generic parameters

        sizerQ   rT   rU   N)rV   r   rW   rX   rH   rI   rY   notnary   r\   r^   r`   ra   rE   rN   r8   rc   sizes
size_ranger>   )
r   r   r   re   rc   rf   rN   r8   r>   r   rh   r   r   r   )  s4   


zSizeMapping.__init__c                 C   s.   |d urd}|S t |ttfrd}|S |}|S )NrT   rU   )rD   rt   rE   )r   rc   r   ru   rN   r   r   r   r\   a  s   zSizeMapping.infer_map_typec                 C   s\   z| j | }W |S  ty-   | |}tj|rtj}| jd |t| j  }Y |S w )Nr   )	r>   rj   rc   rF   rm   rn   ro   r   ptp)r   r?   rp   rq   r   r   r   r@   l  s   
zSizeMapping._lookup_singlec                 C   s   t ||}t|tr't|t| }t|rd| }t|| }||fS t|tr>| ||d}tt	||}||fS t|t
rPt|dkrOd}t|n|d ur]d| }t|| jj}tjg |t|R  d d d }tt	||}||fS )Nz(Missing sizes for the following levels: r      'A `sizes` tuple must have only 2 values"Value for `sizes` not understood: )rw   rD   rt   rx   ry   rz   r   rE   r<   r2   r   r0   r   _default_size_rangerF   linspace)r   rf   r   re   r8   r}   rr   r>   r   r   r   ra   w  s0   


-
'

"zSizeMapping.categorical_mappingc                 C   sJ  t |trttt|}| }t|t|f}n0ttt|	 }t |t
r:t|dkr7d}t||}n|d urGd| }t|| jj}|d u rUtj }n t |t
ratjj| }nt |tjjsqd| }t|t|}d|_| s|| ||}t |tr|}	n|\}
}|
|||
   }tt||}	||	||fS )Nr   r   r   z0Value for size `norm` parameter not understood: T)rD   rt   rE   rF   r   r9   minmaxr   r   r   r0   rz   r   r   r   r~   r   r   clipr   r2   )r   rf   r   rc   r8   size_valuesr   rr   sizes_scaledr>   lohir   r   r   r`     s@   





zSizeMapping.numeric_mappingr   )r   rK   rL   rM   rc   r   r\   r@   ra   r`   r   r   r   rh   r   r   #  s    8:r   c                       s:   e Zd ZdZdZ	d
 fdd	ZdddZdd	 Z  ZS )StyleMappingz8Mapping that sets artist style according to data values.rU   Nc                    sR  t  | |jdtjtd}|  rt	|dkr!t
|}t||}| ||tt|d}| ||tt|d}i }g }| D ]#\}	}
t|
tjjsWtj|
}
|
 |
 ||	< ||
  qFt|rxt|sxd}t|i }|D ]"}i ||< |r|| || d< || || d< |r|| || d< q||| _|| _d	S d	S )
zMap the levels of the `style` variable to distinct values.

        Parameters
        ----------
        # TODO add generic parameters

        stylerQ   r
   markersdashesz+Filled and line art markers cannot be mixedmarkerpathN)rV   r   rW   rX   rH   rI   rY   r   ry   variable_typerE   rw   _map_attributesunique_markersr0   unique_dashesitemsrD   r   r   MarkerStyleget_pathtransformedget_transformappend	is_filledr[   rz   r8   r>   )r   r   r   r   re   rf   r8   pathsfilled_markersrB   mrr   r>   r?   rh   r   r   r     sD   


zStyleMapping.__init__c                 C   s(   |du r| j | }|S | j | | }|S )z(Get attribute(s) for a given data point.Nr=   )r   r?   attrrp   r   r   r   r@   D  s
   
zStyleMapping._lookup_singlec                 C   s   |du rt t||}|S t|t r,t|t| }|r(d| d| }t||}|S t|trA| |||}t t||}|S |rOd| d| }t|i }|S )z5Handle the specification for a given style attribute.TzThese `z` levels are missing values: zThis `z` argument was not understood: )rt   r2   rD   rx   rz   r   r<   )r   argr8   defaultsr   r>   r}   rr   r   r   r   r   L  s&   


zStyleMapping._map_attributesr   r   )	r   rK   rL   rM   rN   r   r@   r   r   r   r   rh   r   r     s    
<r   c                   @   s  e Zd ZdZeeedZdZdddddZ	dddZ
d	Zd
i fddZed1ddZedd Zedd Zd
i fddZd1ddZd1ddZ	
d1ddddddddZedd Zd d! Z	
	
d2d"d#Zd$d% Zd3d'd(Zd)d* Zd+d, Zd-d. Zd2d/d0Zd
S )4VectorPlotterz2Base class for objects underlying *plot functions.)rP   r   r   )r)   yrP   r   r   units@index@values@columns)r)   r   rP   r   r)   r   )r   r   Nc                 C   sh   i | _ ddd| _| || | j D ]\}}t|j| d}t| d| | t| d|   qd S )NFr   r   map_)	_var_levels_var_orderedassign_variables_semantic_mappingsr   r   r$   r   getattr)r   rf   	variablesvarr    map_funcr   r   r   r   x  s   zVectorPlotter.__init__c                 C   s@   |du r| j }i }| D ]\}}||v r|dur|||< q|S )z<Subset a dictionary arguments with known semantic variables.N)	semanticsr   )r    r"   r   r   r?   valr   r   r   get_semantics  s   zVectorPlotter.get_semanticsc                 C   s   t ddht| j@ S )z.Return True at least one of x or y is defined.r)   r   )boolrx   r   r   r   r   r   has_xy_data  s   zVectorPlotter.has_xy_datac              	   C   sF   | j D ]}zt| d| d}|j| j|< W q ty   Y qw | jS )a4  Property interface to ordered list of variables levels.

        Each time it's accessed, it updates the var_levels dictionary with the
        list of levels in the current semantic mappers. But it also allows the
        dictionary to persist, so it can be used to set levels by a key. This is
        used to track the list of col/row levels using an attached FacetGrid
        object, but it's kind of messy and ideally fixed by improving the
        faceting logic so it interfaces better with the modern approach to
        tracking plot variables.

        r   r   )r   r   r8   r   AttributeError)r   r   map_objr   r   r   
var_levels  s   
zVectorPlotter.var_levelsc                    s   | dd}| dd}|du r#|du r#d| _| j|fi |\ }nd| _| j|fi |\ } | _|| _ fdd|D | _| S )z;Define plot variables, optionally using lookup from `data`.r)   Nr   rs   longc                    s*   i | ]}|t  | |d v rdnddqS )xyrT   rU   )boolean_typer   r(   vrW   r   r   
<dictcomp>  s    z2VectorPlotter.assign_variables.<locals>.<dictcomp>)rX   r]   _assign_variables_wideform_assign_variables_longformrW   r   r^   )r   rf   r   r)   r   r   r   r   r     s*   

zVectorPlotter.assign_variablesc                 K   s  dd |  D }t|r-t|dkrdnd}d| d}|dd	d
 |D 7 }t||du p5t| }t|tr@| }n
t	tj
|td}tdd
 |D  }|r`t }	i }
|	|
fS |rt| }|j|jjd}i }	i }
dD ] }|| jv r| j| }t||dd |	|< || j|  |
|< qwt|	}	|	|
fS t|tri }t|D ]\}}t|d|}t|||< q|}t|trdd |  D }tj|dd}dd |  D }|| }ddd}d| j v }|rd|d< z|jj}|jj}|jd|_W n ty   d}Y nw d}|j |d< |jdi |}	|r5|r5t|	d |||	d< | j  D ]\}}|	| |	|< q:i }
| j  D ]\}}t||dd }t|dd|
|< qM|	t |
 }	|	|
fS )a5  Define plot variables given wide-form data.

        Parameters
        ----------
        data : flat vector or collection of vectors
            Data can be a vector or mapping that is coerceable to a Series
            or a sequence- or mapping-based collection of such vectors, or a
            rectangular numpy array, or a Pandas DataFrame.
        kwargs : variable -> data mappings
            Behavior with keyword arguments is currently undefined.

        Returns
        -------
        plot_data : :class:`pandas.DataFrame`
            Long-form data object mapping seaborn variables (x, y, hue, ...)
            to data vectors.
        variables : dict
            Keys are defined seaborn variables; values are names inferred from
            the inputs (or None when no name can be determined).

        c                 S   s   g | ]
\}}|d ur|qS r   r   r(   rB   r   r   r   r   r*         z<VectorPlotter._assign_variables_wideform.<locals>.<listcomp>r   sr%   zThe following variablez) cannot be assigned with wide-form data: z, c                 s   s    | ]	}d | d V  qdS )`Nr   r   r   r   r   	<genexpr>  s    z;VectorPlotter._assign_variables_wideform.<locals>.<genexpr>NrQ   c                 s   s*    | ]}t |tot |ttf V  qd S r   )rD   r   strbytesr   r   r   r   r     s
    
)r   r   r   namec                 S   s   i | ]
\}}|t |qS r   )rH   rI   )r(   r?   r   r   r   r   r   (  r   z<VectorPlotter._assign_variables_wideform.<locals>.<dictcomp>Tr   c                 S   s    g | ]\}}t |d kr|qS rT   r   r   r   r   r   r*   1  s    r   r   )var_name
value_namer   id_varsFr   )!r   ry   r0   r1   rz   rD   rt   r9   rF   
atleast_1dr   objectrH   	DataFramerI   r   r   indexflat_structurer   r   	enumerater   wide_structurecolumns
categoriesorderedadd_categoriesr   	to_seriesmeltCategoricalrE   )r   rf   r"   assignedr   rr   emptyr9   flatrW   r   	flat_datanamesr   r   	data_dictir?   	wide_datanumeric_colsmelt_kws	use_indexorig_categoriesorig_orderedcategory_columnsobjr   r   r   r     s   


]


G



z(VectorPlotter._assign_variables_wideformc           
   
      s  i  i }|du r
i }z|j  }W n ty   i }Y nw | D ]\}}z||v p4t|ttfo4||v }W n ttfyC   d}Y nw |r`||v rQ||  |< n
||v r[||  |< |||< q!t|ttfrtd| d| d}t	|t|t
jrt|t
jst|rt|t|kr|jj}	d|	 dt| d| d	t| d
	}t	|| |< t|dd||< q!t
   fdd| D } |fS )a  Define plot variables given long-form data and/or vector inputs.

        Parameters
        ----------
        data : dict-like collection of vectors
            Input data where variable names map to vector values.
        kwargs : variable -> data mappings
            Keys are seaborn variables (x, y, hue, ...) and values are vectors
            in any format that can construct a :class:`pandas.DataFrame` or
            names of columns or index levels in ``data``.

        Returns
        -------
        plot_data : :class:`pandas.DataFrame`
            Long-form data object mapping seaborn variables (x, y, hue, ...)
            to data vectors.
        variables : dict
            Keys are defined seaborn variables; values are names inferred from
            the inputs (or None when no name can be determined).

        Raises
        ------
        ValueError
            When variables are strings that don't appear in ``data``.

        NFzCould not interpret value `z` for parameter `r   z
Length of zO vectors must match length of `data` when both are used, but `data` has length z and the vector passed to `z` has length .r   c                    s&   i | ]\}} |    r||qS r   )notnullry   )r(   r   r   r   r   r   r     s    z<VectorPlotter._assign_variables_longform.<locals>.<dictcomp>)r   to_framer   r   rD   r   r   rj   rk   rz   rH   r   rI   rF   ndimr0   ri   r   r   )
r   rf   r"   r   r   r?   r   val_as_data_keyrr   val_clsr   r   r   r   [  sZ   


z(VectorPlotter._assign_variables_longformFT)reversefrom_comp_databy_facetallow_emptyr   c             	   #   s.   |du rg }nt |tr|g}n	t |trt|}|r.ddh}||t jt| @   fdd|D }|r= j}n j}|rF|	 } j
 }	|rddht|@ D ]S}
 j|
 dkr j|
 ru j|
 jd	 }||	|
 |	|
< qUt||
  |	|
< qU j|
 d
krtj|	|
 |	|
< qU j|
 dkr |
rt|	|
 |	|
< qU|r|j|ddd}g }|D ]}||	|g  qtj| }|rtt|}|D ]8}t|dkr|d	 n|}z| |}W n t!y   |j"g  }Y nw |j#r|sqt$t%||}|| fV  qdS i | fV  dS )a  Generator for getting subsets of data defined by semantic variables.

        Also injects "col" and "row" into grouping semantics.

        Parameters
        ----------
        grouping_vars : string or list of strings
            Semantic variables that define the subsets of data.
        reverse : bool
            If True, reverse the order of iteration.
        from_comp_data : bool
            If True, use self.comp_data rather than self.plot_data
        by_facet : bool
            If True, add faceting variables to the set of grouping variables.
        allow_empty : bool
            If True, yield an empty dataframe when no observations exist for
            combinations of grouping variables.
        dropna : bool
            If True, remove rows with missing data.

        Yields
        ------
        sub_vars : dict
            Keys are semantic names, values are the level of that semantic.
        sub_data : :class:`pandas.DataFrame`
            Subset of ``plot_data`` for this combination of semantic values.

        Ncolrowc                    s   g | ]	}| j v r|qS r   )r   )r(   r   r   r   r   r*     s    z+VectorPlotter.iter_data.<locals>.<listcomp>r)   r   rU   r   r
   rT   F)r   as_indexr   )&rD   r   r   rE   extendrx   r   	comp_datarW   r   r   r   r^   r   
convertersilocconvert_unitsrF   r   r   r   datesdate2num_log_scaledlog10groupbyr   rX   r3   productreversedr0   	get_grouprj   locr   rt   r2   )r   grouping_varsr
  r  r  r  r   
facet_varsrf   r8   axis	convertergrouped_datagrouping_keysr   	iter_keysr?   pd_keydata_subsetsub_varsr   r   r   	iter_data  sp   #






zVectorPlotter.iter_datac           	   
   C   sD  t | ds| jS t | ds| jjddjddgddd	}d
D ]}}|| jvr&qg }| j| j| j| dd}|D ]M\}}tdd |	 }|| j
v rU||| j
|  }W d   n1 s_w   Y  t||}| dkrwt|}|tj||j|jd q7|rt|}ntjt|d}|d|| q|| _| jS )zFDataframe with numeric x and y, after unit conversion and log scaling.ax
_comp_dataF)deepr)   r   r   ignore)r!  errorsyxr   zmode.use_inf_as_naTNlog)r   )rR   r   r   )hasattrrW   r   dropr   r  r  rH   option_contextr   r   isinr_   r  	get_scalerF   r  r   rI   r   r   concatrY   insertr+  )	r   r  r   partsgroupedr"  origcompcomp_colr   r   r   r  F  s>   




zVectorPlotter.comp_datac                 C   sx   | dd}| dd}|dur|dur| jj||f S |dur&| jj| S |dur0| jj| S | jdu r9| jjS | jS )z>Return an Axes object based on existence of row/col variables.r  Nr  )rX   facets	axes_dictr*  )r   r(  r  r  r   r   r   	_get_axest  s   
zVectorPlotter._get_axesc              	   C   s  ddl m} t||r-d| _|| _|j }|jdur!|j| jd< |j	dur,|j	| jd< n	|| _d| _|g}t
d| j}|du rGg d}nt|trO|g}|D ]}| j| }||vrld| d	| d
| d}	t|	qQddd}
i | _|D ]}ddd| }tj| jj|td}t| jd| d}|du s||
| krt|d | d|jdd< nS|du r|  D ]\}}| |}t|| d|j|j< qn4t| j| d}t|D ]&\}}|dkr|dfnd|f}t| jj| | d}||j| j| |k< q|| j|< | j| j| j| dd}|D ]%\}}| j| dkr4| j| r-| j| }nd}t||}|| qqw|du rFd }}n%z|\}}W n tyj   d| jv r\|nd}d| jv rf|nd}Y nw td||fD ]@\}}|r|D ]5}t|d| d}|du r|d q{t t!j"t dkr|d|d q{|di d| |i q{qr| j#dddkr|D ]!}z	|j$%d W q t&y   |' s|(  Y qw dS dS )a  Associate the plotter with an Axes manager and initialize its units.

        Parameters
        ----------
        obj : :class:`matplotlib.axes.Axes` or :class:'FacetGrid`
            Structural object that we will eventually plot onto.
        allowed_types : str or list of str
            If provided, raise when either the x or y variable does not have
            one of the declared seaborn types.
        log_scale : bool, number, or pair of bools or numbers
            If not False, set the axes to use log scaling, with the given
            base or defaulting to 10. If a tuple, interpreted as separate
            arguments for the x and y axes.

        r   )	FacetGridNr  r  r   rT   r
   rU   r,   z variable is z, but one of z is requiredr   r   r)   )r   r   rR   _shareTr   r!  F_namesr0  rU   set_scaler1  z3.3)baserG  )r1  ))axisgridrA  rD   r*  r>  axesflatten	col_namesr   	row_namesrx   intersectionr   r   r^   rk   r  rH   rI   rW   r   r   r   r  r)  r@  r   r  r   rw   update_unitsr2   r   r   __version__rX   yaxisset_invertedr   yaxis_invertedinvert_yaxis)r   r  allowed_types	log_scalerA  ax_listaxis_variablesr   ru   rr   	facet_dim	other_varr"  share_state	axes_vars	axes_datar*  r   r   levelidxr!  r:  	seed_datare   scalexscaleyrF  	set_scaler   r   r   _attach  s   







	 
	





zVectorPlotter._attachc                 C   s~   t | dsdS | jdu r| jj }n| jg}g }|D ]}t|| d}|| dk qt|r;t	|s;t
dt|S )zAReturn True if specified axis is log scaled on all attached axes.r*  FNr!  r1  zAxis scaling is not consistent)r2  r*  r>  rI  rJ  r   r   r6  ry   r[   RuntimeError)r   r!  	axes_list
log_scaledr*  	data_axisr   r   r   r    s   

zVectorPlotter._log_scaledr%   c                 C   st   |  stdd | D }|j| jd||d | s8tdd | D }|j| jd||d dS dS )zCAdd axis labels if not present, set visibility to match ticklabels.c                 s       | ]}|  V  qd S r   get_visibler(   tr   r   r   r   0      z1VectorPlotter._add_axis_labels.<locals>.<genexpr>r)   )visiblec                 s   rh  r   ri  rk  r   r   r   r   3  rm  r   N)	
get_xlabelry   get_xticklabels
set_xlabelr   rX   
get_ylabelget_yticklabels
set_ylabel)r   r*  	default_x	default_y	x_visible	y_visibler   r   r   _add_axis_labels)  s   zVectorPlotter._add_axis_labelsc                 O      t r   NotImplementedErrorr   r!  r!   r"   r   r   r   scale_native;  s   zVectorPlotter.scale_nativec                 O   rz  r   r{  r}  r   r   r   scale_numericA     zVectorPlotter.scale_numericc                 O   rz  r   r{  r}  r   r   r   scale_datetimeH  r  zVectorPlotter.scale_datetimec                 C   s   t dddg| || jvrd| j|< d| j|< d| j|< | j| dkr,| jj|dd	| _| j| }|dup:|jjd
k| j|< t	t
||}|durU||}||}n
|t}|t}|| j|< d| j|< || j|< | S )a  
        Enforce categorical (fixed-scale) rules for the data on given axis.

        Parameters
        ----------
        axis : "x" or "y"
            Axis of the plot to operate on.
        order : list
            Order that unique values should appear in.
        formatter : callable
            Function mapping values to a string representation.

        Returns
        -------
        self

        r!  r)   r   NrU   r%   rT   	mergesort)kindcategory)r   r   r^   rW   sort_valuesrR   r   r   rH   Indexrw   r$   astyper   r   )r   r!  re   	formattercat_datar   r   r   scale_categoricalO  s&   *



	






zVectorPlotter.scale_categoricalr   )NN)r%   r%   )r   rK   rL   rM   rO   r   r   r   r   r   r   r   r   classmethodr   propertyr   r   r   r   r   r)  r  r@  rc  r  ry  r~  r  r  r  r   r   r   r   r   e  sP    



 
sy
-
 
r   c                       s,   e Zd ZdZdZ fddZdd Z  ZS )VariableTypez
    Prevent comparisons elsewhere in the library from using the wrong name.

    Errors are simple assertions because users should not be able to trigger
    them. If that changes, they should be more verbose.

    rB  c                    s"   || j v s	J |t | d S r   )allowedrV   r   )r   rf   rh   r   r   r     s   zVariableType.__init__c                 C   s   || j v s	J || j|kS r   )r  rf   )r   otherr   r   r   __eq__  s   
zVariableType.__eq__)r   rK   rL   rM   r  r   r  r   r   r   rh   r   r    s
    r  rT   c                 C   s   t jj| rtdS t |  rtdS t ( tj	dt
tfd t| ddtjg r;t|W  d   S W d   n1 sEw   Y  t jj| rUtdS t jj| r`tdS d	d
 }|| rltdS dd }|| rxtdS tdS )a+  
    Determine whether a vector contains numeric, categorical, or datetime data.

    This function differs from the pandas typing API in two ways:

    - Python sequences or object-typed PyData objects are considered numeric if
      all of their entries are numeric.
    - String or mixed-type data are considered categorical even if not
      explicitly represented as a :class:`pandas.api.types.CategoricalDtype`.

    Parameters
    ----------
    vector : :func:`pandas.Series`, :func:`numpy.ndarray`, or Python sequence
        Input data to test.
    boolean_type : 'numeric' or 'categorical'
        Type to use for vectors containing only 0s and 1s (and NAs).

    Returns
    -------
    var_type : 'numeric', 'categorical', or 'datetime'
        Name identifying the type of data in the vector.
    rU   rT   r-  )actionr  r   r   Nr
   c                 S   s   | D ]
}t |ts dS qdS NFT)rD   r	   r)   x_ir   r   r   all_numeric  s
   
z"variable_type.<locals>.all_numericc                 S   s$   | D ]}t |ttjfs dS qdS r  )rD   r
   rF   
datetime64r  r   r   r   all_datetime  s
   z#variable_type.<locals>.all_datetime)rH   apitypesis_categorical_dtyper  rZ   r[   r5   catch_warningssimplefilterFutureWarningDeprecationWarningrF   r5  ro   is_numeric_dtypeis_datetime64_dtype)vectorr   r  r  r   r   r   r     s0   

r   Tc           	      C   s  | du rdnt | }|du rdnt |}d}d}| du r<t|dr,t|dd |r:|dkr:t|ddd	S |du r`t|d	rPt|dd
 |r^|dkr^t|dd
dS t|d	rw|ru|dkrut|ddd	S t|dr|r|dkrt|dd
dS |durdt| d}t||dkr|dkrdS |dkr|dkrd	S |dkr|dkrdS |rd||fvrd}t|d	S )aW  Determine how the plot should be oriented based on the data.

    For historical reasons, the convention is to call a plot "horizontally"
    or "vertically" oriented based on the axis representing its dependent
    variable. Practically, this is used when determining the axis for
    numerical aggregation.

    Parameters
    ----------
    x, y : Vector data or None
        Positional data vectors for the plot.
    orient : string or None
        Specified orientation, which must start with "v" or "h" if not None.
    require_numeric : bool
        If set, raise when the implied dependent variable is not numeric.

    Returns
    -------
    orient : "v" or "h"

    Raises
    ------
    ValueError: When `orient` is not None and does not start with "h" or "v"
    TypeError: When dependent variable is not numeric, with `require_numeric`

    Nz.{} orientation requires numeric `{}` variable.z0{} orientation ignored with only `{}` specified.h
Horizontalr   rT   Verticalr   r)   z5`orient` must start with 'v' or 'h' or be None, but `z` was passed.rU   z7Neither the `x` nor `y` variable appears to be numeric.)	r   r   
startswithr5   r6   r{   rk   reprrz   )	r)   r   orientrequire_numericx_typey_typenonnumeric_dv_errorsingle_var_warningrr   r   r   r   infer_orient  sP   r  c                    s   g d}d}t || k r[tddg|}tddg|}tjtt|dd ddd t|dd  }|D ]}t| ttj fdd	|D  }|| q7|d7 }t || k s|d|  S )
a  Build an arbitrarily long list of unique dash styles for lines.

    Parameters
    ----------
    n : int
        Number of unique dash specs to generate.

    Returns
    -------
    dashes : list of strings or tuples
        Valid arguments for the ``dashes`` parameter on
        :class:`matplotlib.lines.Line2D`. The first spec is a solid
        line (``""``), the remainder are sequences of long and short
        dashes.

    )r%   )rS         ?)r   r   )         ?r  r  )   r   r   r   r  r  rS   r   r   Nc                 3   s    | ]}| fV  qd S r   r   )r(   seggapr   r   r     rm  z unique_dashes.<locals>.<genexpr>)	r0   r3   combinations_with_replacementchainr2   rE   r   r   r   )nr   pabsegment_listsegmentsspecr   r  r   r   f  s    	r   c                 C   sz   g d}d}t || k r7d|d  d }||d d|f|d d|f|ddf|ddfg |d7 }t || k s|d|  S )aW  Build an arbitrarily long list of unique marker styles for points.

    Parameters
    ----------
    n : int
        Number of unique marker specs to generate.

    Returns
    -------
    markers : list of string or tuples
        Values for defining :class:`matplotlib.markers.MarkerStyle` objects.
        All markers will be filled.

    )	oX)rS   r   -   P)rS   r   r   )rS   r   r   ^)rS   r   r  r   r  ih  r   r   r   N)r0   r  )r  r   r   r  r   r   r   r     s   r   c                 C   s   |du rEt | dr| j}n2z| jj}W n+ ttfy>   z|  }W n ty0   t| }Y nw t| dkr<t	|}Y nw t
tj|}t|S )a  Return a list of unique data values.

    Determine an ordered list of levels in ``values``.

    Parameters
    ----------
    vector : list, array, Categorical, or Series
        Vector of "categorical" values
    order : list-like, optional
        Desired order of category levels to override the order determined
        from the ``values`` object.

    Returns
    -------
    order : list
        Ordered list of category levels not including null values.

    Nr   rT   )r2  r   catrk   r   r   rH   r   rF   r   filterr  rE   )r  re   r   r   r   rw     s"   


rw   r   )NNNTr   )*r5   r3   r   	functoolsr   collectionsr   collections.abcr   r   r   numbersr	   r
   numpyrF   pandasrH   
matplotlibr   _decoratorsr   external.versionr   palettesr   r   utilsr   r   r   r   rO   r   r   r   r  r   r  r   r   rw   r   r   r   r   <module>   sJ    A E ^c      N

SR3.