o
    0GfE                     @   s0   d dl ZddlmZ 							d	ddZdS )
    N   )utilsFTbothc           C         s
  ddl m} t|\}}t| } dd }||}||}||}||}t| }|du r3t|}|du r<t|}|du rEt|}d}tt	|}|durWtt	|}|du r`d}d}n|du rid}|}n|dk}|dkrs|nd}|| }|
d	 |d	 |du rtt	|}|  n|}|	du rtt	|}|  n|	}i }t|D ]/}|dur|| |vrq|	dur|| |	vrq|| || f} | |vrg || < ||  | q| |j }!|!j|!j}"}#t|}$d
\}%}&|r||j|j}'n||j|j}'||# }(|r|&|% ||(  t|$ })n|&|% t|$ })|dur+|n
tt	|  |r?ddd t}*|*dkrS|)dt|*d   }+nd}+fddD },g d}-|du rndd D }t|*D ];}.|. }/d||/ vr|-|.t|-  ||/ d< d||/ vrd||/ d< d||/ vr|+dkrdnd||/ d< qr|du rdd D }t|*D ](}.|. }/d||/ vrd||/ d< d||/ vr|+dkrdnd||/ d< q|r|dkr|&|)d  n|&}0n|%|)d  }0t	 }1g }2|D ]e |r|rO |d kr|0|)d  n|0}3|jd
|3|3f|0d|(  |0d|(  fd|jdd |jd|0d |(   d!d!|jd"}4|4d# |0|(8 }0nEt fd$d%|D }5|j|0|)d  d& |0|5d |)  |)d  d& fd'd(d|jddd) |j|0|5d |) d  d* d!d+|jd"}4|4d# d}6|D ]}7 |7f|vrq|r|j|0dd, n|j|0dd, |dur|7|}8t|8dkr|8d |8d }9}:n|7d}9}:n|7d}9}:|dur||9}9|dur||:}:|r2|6d dkr2|r|jd
|0|)d  |0|)d  f|0|)d  |0|)d  fd-|jdd n|j|0|)d  |0|)d  fd.d/d-|jdd |6d7 }6|  d0v r_|rP|jd1|" |0|9d2d!|jd3d4 n|j|0d1|# |9d!d5|jd3d4 |  d6v r|:dur|r|jdd7|"  |0|:d8d!|jd3d4 n|j|0dd7|#  |:d!d+|jd3d4 |2|0 t!| |7f D ]\};}<d}=|
r|) d9 |,||<  |+  }=| |< }>|durt"||< r|>||<  |>||<  }?}@n|>||< d  |>||< d  }?}@|r|j#|?|@g|0|= |0|= gd:fd;|'i|||<   n|j#|0|= |0|= g|?|@gd:fd;|'i|||<   ||< }A|A|1vr%|And}B|1$|A |rE|j#|>g|0|= gfd<|'|Bd=||A  q|j#|0|= g|>gfd<|'|Bd=||A  q|rd|0|)8 }0q|0|)7 }0qq|r|j%&d+ |j'&d> |(g  |j)d8 *d> |j)d2 *d> |j)d5 *d> |j)d+ +d?d1|# f |,dd |j'-|2 |j.ddd@ |S |j'&d8 |j%&d> |/g  |j)d+ *d> |j)d2 *d> |j)d5 *d> |j)d8 +d?d1|" f |0dd |j%-|2 |j.dddA |S )Ba-  
    Dot plotting (also known as forest and blobbogram).

    Produce a dotplot similar in style to those in Cleveland's
    "Visualizing Data" book ([1]_).  These are also known as "forest plots".

    Parameters
    ----------
    points : array_like
        The quantitative values to be plotted as markers.
    intervals : array_like
        The intervals to be plotted around the points.  The elements
        of `intervals` are either scalars or sequences of length 2.  A
        scalar indicates the half width of a symmetric interval.  A
        sequence of length 2 contains the left and right half-widths
        (respectively) of a nonsymmetric interval.  If None, no
        intervals are drawn.
    lines : array_like
        A grouping variable indicating which points/intervals are
        drawn on a common line.  If None, each point/interval appears
        on its own line.
    sections : array_like
        A grouping variable indicating which lines are grouped into
        sections.  If None, everything is drawn in a single section.
    styles : array_like
        A grouping label defining the plotting style of the markers
        and intervals.
    marker_props : dict
        A dictionary mapping style codes (the values in `styles`) to
        dictionaries defining key/value pairs to be passed as keyword
        arguments to `plot` when plotting markers.  Useful keyword
        arguments are "color", "marker", and "ms" (marker size).
    line_props : dict
        A dictionary mapping style codes (the values in `styles`) to
        dictionaries defining key/value pairs to be passed as keyword
        arguments to `plot` when plotting interval lines.  Useful
        keyword arguments are "color", "linestyle", "solid_capstyle",
        and "linewidth".
    split_names : str
        If not None, this is used to split the values of `lines` into
        substrings that are drawn in the left and right margins,
        respectively.  If None, the values of `lines` are drawn in the
        left margin.
    section_order : array_like
        The section labels in the order in which they appear in the
        dotplot.
    line_order : array_like
        The line labels in the order in which they appear in the
        dotplot.
    stacked : bool
        If True, when multiple points or intervals are drawn on the
        same line, they are offset from each other.
    styles_order : array_like
        If stacked=True, this is the order in which the point styles
        on a given line are drawn from top to bottom (if horizontal
        is True) or from left to right (if horizontal is False).  If
        None (default), the order is lexical.
    striped : bool
        If True, every other line is enclosed in a shaded box.
    horizontal : bool
        If True (default), the lines are drawn horizontally, otherwise
        they are drawn vertically.
    show_names : str
        Determines whether labels (names) are shown in the left and/or
        right margins (top/bottom margins if `horizontal` is True).
        If `both`, labels are drawn in both margins, if 'left', labels
        are drawn in the left or top margin.  If `right`, labels are
        drawn in the right or bottom margin.
    fmt_left_name : callable
        The left/top margin names are passed through this function
        before drawing on the plot.
    fmt_right_name : callable
        The right/bottom marginnames are passed through this function
        before drawing on the plot.
    show_section_titles : bool or None
        If None, section titles are drawn only if there is more than
        one section.  If False/True, section titles are never/always
        drawn, respectively.
    ax : matplotlib.axes
        The axes on which the dotplot is drawn.  If None, a new axes
        is created.

    Returns
    -------
    fig : Figure
        The figure given by `ax.figure` or a new instance.

    Notes
    -----
    `points`, `intervals`, `lines`, `sections`, `styles` must all have
    the same length whenever present.

    References
    ----------
    .. [1] Cleveland, William S. (1993). "Visualizing Data". Hobart Press.
    .. [2] Jacoby, William G. (2006) "The Dot Plot: A Graphical Display
       for Labeled Quantitative Values." The Political Methodologist
       14(1): 6-14.

    Examples
    --------
    This is a simple dotplot with one point per line:

    >>> dot_plot(points=point_values)

    This dotplot has labels on the lines (if elements in
    `label_values` are repeated, the corresponding points appear on
    the same line):

    >>> dot_plot(points=point_values, lines=label_values)
    r   Nc                 S   s   | d u rd S t | S )N)npasarray)x r   =lib/python3.10/site-packages/statsmodels/graphics/dotplots.py<lambda>   s    zdot_plot.<locals>.<lambda>g      ?FTr   g{Gz?)r   r   g      @g        c                    s   i | ]}|  |qS r   )index.0r   )style_codesr   r	   
<dictcomp>   s    zdot_plot.<locals>.<dictcomp>)rgbykZpurpleZorangec                 S      i | ]}|i qS r   r   r   r   r   r	   r         colorZmarkeroms
      c                 S   r   r   r   r   r   r   r	   r     r   ZgreyZ	linewidth      gffffff?Zdarkgrey)r   	transformzordergffffff?center)horizontalalignmentverticalalignmentr   Zboldc                    s   g | ]
}|d   kr|qS )r   r   )r   r   )k0r   r	   
<listcomp>=  s    zdot_plot.<locals>.<listcomp>g{Gz?))\(?r&   )(\?r'   )r   r   r    Zclip_ongRQ?bottom)r   Z	lightgrey)r   r   )r   r   )leftr   grightZ	monospace)r"   r#   r   Zfamilytop)r*   r   g?r)      -r   None)Zlsr   ZlabelZnoneZaxes)Zscaleytight)Zscalexr/   )1Zmatplotlib.transforms
transformsr   Zcreate_mpl_axr   r   lenZarangeZzerossetZset_xmarginZset_ymarginlistsortrangeappendZget_window_extentZtransformedZdpi_scale_transinvertedwidthZheightZblended_transform_factoryZ	transDataZ	transAxesfloatZfill_betweentextZset_fontweightZaxhlineZaxvlinesplitlower	enumerateZisscalarZplotaddZxaxisZset_ticks_positionZyaxisZset_yticklabelsZspinesZ	set_colorZset_positionZset_ylimZ	set_ticksZautoscale_viewZset_xticklabelsZset_xlim)CZpointsZ	intervalslinesZsectionsZstylesZmarker_propsZ
line_propsZsplit_namesZsection_orderZ
line_orderZstackedZstyles_orderZstripedZ
horizontalZ
show_namesZfmt_left_nameZfmt_right_nameZshow_section_titlesZaxr0   ZfigZasarray_or_noneZnpointZsection_title_spaceZnsectZdraw_section_titlesZnsect_titleZsection_space_totalZlines0Zlines1Z	lines_mapikyZbboxZawidthZaheightZnrowsr(   r+   ZtransZtitle_space_axesZdposZnvalZstackdZstyle_codes_mapZcolorsjZscposZlabeledZticksZy0ZtxtmZjrowZk1usZ
left_labelZright_labelZjiZjpZyoptZlcbZucbslZsllr   )r$   r   r	   dot_plot   s  w

































  

rH   )NNNNNNNNNFNFTr   NNNN)Znumpyr    r   rH   r   r   r   r	   <module>   s    