
    I.e!                         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 ddlmZmZ e	 	 	 	 	 dd            ZdS )    )partialN)Version   )_transfer_opts_cur_backend)HoloViewsConverter)with_hv_extension_convert_col_names_to_strscatterhist      ?皙?Fc                 b	   t          j        t          |                     } t          t          j                  }||vrt          d| d|           |vrt          d| d           t          j        |         }t          j                 |s|rP	 ddl}n# t          $ r t          d          w xY wddl	m
} |t          d	          k    rt          j        d
           |r|rt          d          |s|s|s|rt          d          |r4ddlmc m} |s|r'|j        t          d          k     rt#          d          |s|r'ddlmc m} i }d|v r|                    d          |d<   i }|rd|v r|                    d          |d<   d|v r|                    d          |d<   d|v r|                    d          |d<   d|v r|                    d          |d<   d|v r|                    d          |d<   |rpd|v r|                    d          |d<   d|v r|                    d          |d<   d|v r|                    d          |d<   d|v r|                    d          |d<   |pddg}t'          d*|||d|}ry|r|rt)          d          t+          t-          j        |                                                   }|p|pd}t           j        j	                            ||d          }||d<   t           j                            | |          }r|d<   |                    fd d!          }t           j                            |                                                               |"          }||z                      fd#t           j                  }|	r|
s|	r|s|
r|rt)          d$          |	p|
p|pi }rt          j         |          |d%<   |!                    j"        ||j"        |id&'          }|s|r|r|j#        n|j$        }|                    tK          |fi |(          }|s|rQ|r|j&        n|r|j'        nd) }|rt           j(        nt           j)        }|                    tK          |fi ||(          }tU          |          }|S )+a
  
    Scatter matrix of numeric columns.

    A scatter_matrix shows all the pairwise relationships between the columns.
    Each non-diagonal plots the corresponding columns against each other,
    while the diagonal plot shows the distribution of each individual column.

    This function is closely modelled on :func:`pandas.plotting.scatter_matrix`.

    Parameters:
    -----------
    data: DataFrame
        The data to plot. Every column is compared to every other column.
    c: str, optional
        Column to color by
    chart: str, optional
        Chart type for the off-diagonal plots (one of 'scatter', 'bivariate', 'hexbin')
    diagonal: str, optional
        Chart type for the diagonal plots (one of 'hist', 'kde')
    alpha: float, optional
        Transparency level for the off-diagonal plots
    nonselection_alpha: float, optional
        Transparency level for nonselected object in the off-diagonal plots
    tools: list of str, optional
        Interaction tools to include
        Defaults are 'box_select' and 'lasso_select'
    cmap/colormap: str or colormap object, optional
        Colormap to use when ``c`` is set.
        Default is `Category10 <https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md#category10>`.
    diagonal_kwds/hist_kwds/density_kwds: dict, optional
        Keyword options for the diagonal plots
    datashade (default=False):
        Whether to apply rasterization and shading (colormapping) using
        the Datashader library, returning an RGB object instead of
        individual points
    rasterize (default=False):
        Whether to apply rasterization using the Datashader library,
        returning an aggregated Image (to be colormapped by the
        plotting backend) instead of individual points
    dynspread (default=False):
        For plots generated with datashade=True or rasterize=True,
        automatically increase the point size when the data is sparse
        so that individual points become more visible.
        kwds supported include ``max_px``, ``threshold``,  ``shape``, ``how`` and ``mask``.
    spread (default=False):
        Make plots generated with datashade=True or rasterize=True
        increase the point size to make points more visible, by
        applying a fixed spreading of a certain number of cells/pixels. kwds
        supported include: ``px``, ``shape``, ``how`` and ``mask``.
    kwds: Keyword options for the off-diagonal plots and datashader's spreading , optional

    Returns:
    --------
    obj : HoloViews object
        The HoloViews representation of the plot.

    See Also
    --------
        :func:`pandas.plotting.scatter_matrix` : Equivalent pandas function.
    zdiagonal type must be one of: z, found zChart type must be one of: r   Nz;rasterize and datashade require datashader to be installed.r   )
hv_versionz1.14.6zVersions of holoviews before 1.14.7 did not support dynamic update of rasterized/datashaded scatter matrix. Update holoviews to a newer version.zEChoose to either rasterize or datashade the scatter matrix, not both.zBdynspread or spread need rasterize or datashade to be set to True.z0.12.0z_Any version of datashader less than 0.12.0 does not support rasterize with dynspread or spread.
aggregatormax_px	thresholdshapehowmaskpx
box_selectlasso_select)alphatoolsnonselection_alphaz"Only specify `cmap` or `colormap`.
Category10T)ncolorscategoricalcmap)diagonal_type
chart_typecolorc                 B    |                      | j        gz             S )N)vdims)cloner$   )xcs    >lib/python3.11/site-packages/hvplot/plotting/scatter_matrix.py<lambda>z scatter_matrix.<locals>.<lambda>   s    !'''"<"<     Scatter)r!   r    c                     t          |                     d                    r|                     d          n|                     d          S )Nr      )
isinstanceget)r&   charts    r(   r)   z scatter_matrix.<locals>.<lambda>   s>    AEE!HHe9T9T-bQUU1XXXZ[Z_Z_`aZbZb r*   zGSpecify at most one of `diagonal_kwds`, `hist_kwds`, or `density_kwds`.
fill_colorbokeh)backend)specsc                     | S )N )z_s     r(   r)   z scatter_matrix.<locals>.<lambda>   s    _` r*   r6   )+_hvDatasetr	   listr   _kind_mapping
ValueError
datashaderImportErrorutilr   r   warningswarnholoviews.operation.datashader	operation
ds_versionRuntimeErrorpopdict	TypeErrorlen_npuniquedimension_valuesplottingprocess_cmap
gridmatrixmapgroupbyoverlayOverlayCycleoptions__name__	datashade	rasterizer   	dynspreadspreadRGBImager   )datar'   r0   diagonalr   r   r   r   colormapdiagonal_kwds	hist_kwdsdensity_kwdsrX   rY   rZ   r[   kwds	supportedr>   r   hdds_kwdssp_kwds
chart_optsr   gridgroupsdiagonal_optsaggregatefnspreadfneltypes    ``                            r(   scatter_matrixrp      sY   H ;06677D'566Iy  W)WWXWWXXXIQyQQ%QQRRR!/9H,U3E I 	= 	= 	= 	= < = = =	= 	&%%%%%****M7    DY D C D D 	D  <Y <F <i < ; < < 	<  G333333333 	G 	G}wx0000"FG G G
  ;I ;3333333334$(HH\$:$:GL! G 
/t $ 2 2GH$#'88K#8#8GK d??#xx00GGD==!XXe__GENT>>"hhv..GFO /4<< HHTNNGDMd??#xx00GGD==!XXe__GENT>>"hhv..GFO3lN3E EE);E E?CE EJ " 	BH 	B@AAAcj!6!6q!9!9::;;/x/<| --dGQU-VV!
6 =##DU#SSD 0
7xx<<<<iHH ))$,,q//*A*A*C*C5:8@ * B B v""#b#b#b#b#&;0 0 	 +) ++&++"+  * + + 	+ "DYD,D"M 6&)iool#<<	X%6F   D  HI H&/AbllR\xx77w77uxEE 	HY 	H'0ar||F7`ryyP`P`H )8SWWsyF88GH88888GGD%d++DKs   B B7)Nr
   r   r   r   NNNNNNFFFF)	functoolsr   rA   	holoviewsr9   numpyrK   packaging.versionr   backend_transformsr   	converterr   r@   r   r	   rp   r6   r*   r(   <module>rw      s                   % % % % % % ; ; ; ; ; ; * * * * * * ? ? ? ? ? ? ? ? ;A1437DHMR	     r*   