U
    ÃmœdïE  ã                   @   s"   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krft |¡}|dkrxt |¡}|dkrŠt |¡}d}tt	|ƒƒ}|dk	r®tt	|ƒƒ}|dkrÀd}d}n*|dkrÒd}|}n|dk}|dkræ|nd}|| }| 
d	¡ | d	¡ |dk�r&tt	|ƒƒ}| ¡  n|}|	dk�rJtt	|ƒƒ}| ¡  n|	}i }t|ƒD ]n}|dk	�rz|| |k�rz�qZ|	dk	�r–|| |	k�r–�qZ|| || f} | |k�r¸g || < ||   |¡ �qZ| ¡  |j ¡ ¡}!|!j|!j }"}#t|ƒ}$d
\}%}&|�r| |j|j¡}'n| |j|j¡}'||# }(|�rL|&|% ||(  t|$ƒ })n|&|% t|$ƒ })|dk	�rl|‰ntt	|ƒƒ‰ˆ ¡  |�r”ˆddd… ‰tˆƒ}*|*dk�r¼|)dt|*ƒd   }+nd}+‡fdd„ˆD ƒ},dddddddg}-|dk�rüdd„ ˆD ƒ}t|*ƒD ]v}.ˆ|. }/d||/ k�r6|-|.t|-ƒ  ||/ d< d||/ k�rPd||/ d< d||/ k�r|+dk�rldnd||/ d< �q|dk�r”dd„ ˆD ƒ}t|*ƒD ]P}.ˆ|. }/d||/ k�rÂd||/ d< d ||/ k�rœ|+dk�rÞd!nd"||/ d < �qœ|�r|dk�r
|&|)d!  n|&}0n|%|)d!  }0t	ƒ }1g }2|D �]È‰ |�rH|�r¾ˆ |d k�rV|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 }0nŠt‡ 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!  d0ˆ d'd1|jd(�}4|4 d)¡ d}6|D �]ž}7ˆ |7f|k�rh�qP|�r~|j|0dd2� n|j|0dd2� |dk	�rÎ|7 |¡}8t|8ƒd!k�rÂ|8d |8d  }9}:n
|7d }9}:n
|7d }9}:|dk	�rê||9ƒ}9|dk	�rü||:ƒ}:|�r„|6d! dk�r„|�rX|jd
|0|)d!  |0|)d!  f|0|)d!  |0|)d!  fd3|jdd%� n,|j|0|)d!  |0|)d!  fd4d5d3|jdd%� |6d7 }6|  ¡ d6k�rÞ|�rÀ|jd7|" |0|9d8d'|jd9d:� n|j|0d7|# |9d'd;|jd9d:� |  ¡ d<k�rB|:dk	�rB|�r |jdd=|"  |0|:d>d'|jd9d:� n"|j|0dd=|#  |:d'd1|jd9d:� |2 |0¡ t!|ˆ |7f ƒD �]v\};}<d}=|
�rŠ|) d? |,||<  |+  }=| |< }>|dk	�rVt "||< ¡�rÈ|>||<  |>||<   }?}@n"|>||< d  |>||< d   }?}@|�r$|j#|?|@g|0|= |0|= gd@fdA|'i|||<  —Ž n2|j#|0|= |0|= g|?|@gd@fdA|'i|||<  —Ž ||< }A|A|1k�rl|And}B|1 $|A¡ |�rª|j#|>g|0|= gfdB|'|BdCœ||A —Ž n(|j#|0|= g|>gfdB|'|BdCœ||A —Ž �q\|�ræ|0|)8 }0n|0|)7 }0�qP�q*|�	rŽ|j% &d1¡ |j' &dD¡ | (g ¡ |j)d>  *dD¡ |j)d8  *dD¡ |j)d;  *dD¡ |j)d1  +dEd7|# f¡ | ,dd¡ |j' -|2¡ |j.dddF� n�|j' &d>¡ |j% &dD¡ | /g ¡ |j)d1  *dD¡ |j)d8  *dD¡ |j)d;  *dD¡ |j)d>  +dEd7|" f¡ | 0dd¡ |j% -|2¡ |j.dddG� |S )Ha-  
    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 krd S t  | ¡S )N)ÚnpÚasarray)Úx© r   úV/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/statsmodels/graphics/dotplots.pyÚ<lambda>ƒ   ó    zdot_plot.<locals>.<lambda>g      à?FTr   g{®Gáz”?)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ÚkÚpurpleZorangec                 S   s   i | ]
}|i “qS r   r   r   r   r   r	   r     s      ÚcolorÚmarkerÚoÚmsé
   é   c                 S   s   i | ]
}|i “qS r   r   r   r   r   r	   r     s      ZgreyZ	linewidthé   é   gffffffæ?Zdarkgrey)r   Ú	transformÚzordergffffffÖ?Úcenter)ÚhorizontalalignmentÚverticalalignmentr    Úboldc                    s   g | ]}|d  ˆ kr|‘qS )r   r   )r   r   )Úk0r   r	   Ú
<listcomp>=  s      zdot_plot.<locals>.<listcomp>g{®Gáz„?)ç)\�Âõ(ð?r(   )çö(\�Âõð?r)   )r   r    r!   Zclip_ongR¸…ëQð?Úbottom)r   Z	lightgrey)r   r   )r   r   )Úleftr   gš™™™™™¹¿ÚrightZ	monospace)r#   r$   r    ÚfamilyÚtop)r,   r   gš™™™™™¹?r+   é   ú-r    ÚNone)Zlsr    ÚlabelÚnoneZaxes)ZscaleyÚtight)Zscalexr4   )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ÚwidthÚ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ÚlinesÚsectionsÚstylesZmarker_propsZ
line_propsZsplit_namesZsection_orderZ
line_orderZstackedZstyles_orderZstripedÚ
horizontalZ
show_namesZfmt_left_nameZfmt_right_nameZshow_section_titlesZaxr5   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_mapÚcolorsÚjÚscÚposZlabeledZticksZy0ÚtxtÚmZjrowZk1ÚusZ
left_labelZright_labelZjiÚjpZyoÚptZlcbZucbÚslZsllr   )r&   r   r	   Údot_plot   s   w










ÿÿÿÿ






ÿûý

ÿ  ûý






ü üüü
üü



ÿÿÿ
þÿ
þ
 ÿþ ÿþ



rU   )NNNNNNNNNFNFTr   NNNN)Únumpyr   Ú r   rU   r   r   r   r	   Ú<module>   s$                            ú