
    M/PhE                     0    d dl ZddlmZ 	 	 	 	 	 	 	 ddZdS )	    N   )utilsFTbothc                 Z  CD ddl m} t          j        |          \  }}t	          j        |           } d } ||          } ||          } ||          } ||          }t          |           }|t	          j        |          }|t	          j        |          }|t	          j        |          }d}t          t          |                    }|t          t          |                    }|du rd}d}n|du rd}|}n|dk    }|dk    r|nd}||z  }|
                    d           |                    d           |1t          t          |                    }|                                 n|}|	1t          t          |                    }|                                 n|	}i }t          |          D ]P}|||         |vr|	||         |	vr||         ||         f} | |vrg || <   ||                              |           Q|                                                    |j                                                  }!|!j        |!j        }#}"t          |          }$d	\  }%}&|r!|                    |j        |j                  }'n |                    |j        |j                  }'||#z  }(|r|&|%z
  ||(z  z
  t3          |$          z  })n|&|%z
  t3          |$          z  })||Dn0t          t          |                    DD                                 |rDddd
         Dt          D          }*|*dk    r|)dt3          |*          dz
  z  z  }+nd}+DfdDD             },g d}-|d DD             }t          |*          D ]g}.D|.         }/d||/         vr!|-|.t          |-          z           ||/         d<   d||/         vrd||/         d<   d||/         vr|+dk    rdnd||/         d<   h|d DD             }t          |*          D ]<}.D|.         }/d||/         vrd||/         d<   d||/         vr|+dk    rdnd||/         d<   =|r|dk    r|&|)dz  z
  n|&}0n|%|)dz  z   }0t                      }1g }2|D ]C|r#|rC|d         k    r|0|)dz  z   n|0}3|                    d	|3|3f|0d|(z  z
  |0d|(z  z
  fd|j        d           |                    d|0d|(z  z
  Cdd|j                   }4|4                    d!           |0|(z  }0nt          Cfd"|D                       }5|                    |0|)dz  z
  d#z   |0|5dz
  |)z  z   |)dz  z   d#z
  fd$d%d|j        dd&           |                    |0|5dz
  |)z  dz  z   d'Cdd(|j                   }4|4                    d!           d}6|D ]S}7C|7f|vr
|r|                    |0d)           n|                    |0d)           |>|7                    |          }8t          |8          dk    r|8d         |8d         }:}9n	|7d}:}9n|7d}:}9| ||9          }9| ||:          }:|rv|6dz  dk    rm|r=|                    d	|0|)dz  z
  |0|)dz  z
  f|0|)dz  z   |0|)dz  z   fd*|j        d           n.|                    |0|)dz  z
  |0|)dz  z   fd+d,d*|j        d           |6dz  }6|                                 d-v rK|r%|                    d.|"z  |0|9d/d|j        d01           n$|                    |0d.|#z  |9dd2|j        d01           |                                 d3v rS|:Q|r(|                    dd4|"z  z   |0|:d5d|j        d01           n'|                    |0dd4|#z  z   |:dd(|j        d01           |2                    |0           tC          |C|7f                   D ]7\  };}<d}=|
r|) d6z  |,||<                  |+z  z   }=| |<         }>|t	          j"        ||<                   r|>||<         z
  |>||<         z   }@}?n"|>||<         d         z
  |>||<         d         z   }@}?|r) |j#        |?|@g|0|=z   |0|=z   gd7fd8|'i|||<                   n( |j#        |0|=z   |0|=z   g|?|@gd7fd8|'i|||<                   ||<         }A|A|1vr|And}B|1$                    |A           |r  |j#        |>g|0|=z   gfd9|'|Bd:||A           |j#        |0|=z   g|>gfd9|'|Bd:||A          9|r|0|)z  }0N|0|)z  }0U|r|j%        &                    d(           |j'        &                    d;           |(                    g            |j)        d5         *                    d;           |j)        d/         *                    d;           |j)        d2         *                    d;           |j)        d(         +                    d<d.|#z  f           |,                    dd           |j'        -                    |2           |.                    dd=           n|j'        &                    d5           |j%        &                    d;           |/                    g            |j)        d(         *                    d;           |j)        d/         *                    d;           |j)        d2         *                    d;           |j)        d5         +                    d<d.|"z  f           |0                    dd           |j%        -                    |2           |.                    dd>           |S )?a-  
    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                 2    | d nt          j        |           S )N)npasarray)xs    ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/graphics/dotplots.py<lambda>zdot_plot.<locals>.<lambda>   s    
1     g      ?FTr   g{Gz?)r   r   g      @g        c                 <    i | ]}|                     |          S  )index).0r
   style_codess     r   
<dictcomp>zdot_plot.<locals>.<dictcomp>   s)    DDD1q+++A..DDDr   )rgbykpurpleorangec                     i | ]}|i S r   r   r   r
   s     r   r   zdot_plot.<locals>.<dictcomp>  s    333!2333r   colormarkeroms
      c                     i | ]}|i S r   r   r   s     r   r   zdot_plot.<locals>.<dictcomp>  s    111a111r   grey	linewidth      gffffff?darkgrey)r   	transformzordergffffff?center)horizontalalignmentverticalalignmentr*   boldc                 ,    g | ]}|d          k    |S )r   r   )r   r   k0s     r   
<listcomp>zdot_plot.<locals>.<listcomp>=  s"    <<<q1r   g{Gz?))\(?r3   )(\?r4   )r   r*   r+   clip_ongRQ?bottom)r   	lightgrey)r   r   )r   r   )leftr   gright	monospace)r-   r.   r*   familytop)r9   r   g?r8      -r*   None)lsr*   labelnoneaxes)scaleytight)scalexrE   )1matplotlib.transforms
transformsr   create_mpl_axr   r	   lenarangezerossetset_xmarginset_ymarginlistsortrangeappendget_window_extenttransformeddpi_scale_transinvertedwidthheightblended_transform_factory	transData	transAxesfloatfill_betweentextset_fontweightaxhlineaxvlinesplitlower	enumerateisscalarplotaddxaxisset_ticks_positionyaxisset_yticklabelsspines	set_colorset_positionset_ylim	set_ticksautoscale_viewset_xticklabelsset_xlim)Epoints	intervalslinessectionsstylesmarker_props
line_propssplit_namessection_order
line_orderstackedstyles_orderstriped
horizontal
show_namesfmt_left_namefmt_right_nameshow_section_titlesaxrH   figasarray_or_nonenpointsection_title_spacensectdraw_section_titlesnsect_titlesection_space_totallines0lines1	lines_mapikybboxawidthaheightnrowsr6   r<   transtitle_space_axesdposnvalstackdstyle_codes_mapcolorsjscposlabeledticksy0txtmjrowk1us
left_labelright_labeljijpyoptlcbucbslsllr1   r   sE                                                                      @@r   dot_plotr      s   n /.....!"%%GC ZFEEO	**IOE""Ex((H_V$$F [[F }	&!! 8F## ~&!!  HE C&&'' e###		$	$"#ai$qyyeea .; NN4NN4c(mm$$c%jj!! I6]]    $!M)I)I!eAhj&@&@qk58$YIbM"Q !!--$$&&( (Dj$+GF 	NNE
 KFC C44R\57\C C 44R\57\C C +W4  -f{+;;;%LL fe, "3v;;''  (!$$B$'{DaxxeDkk!m,- EDDDDDDO ;::F33{3334[[ > >^,r***(.q3v;;(?LW%<+++),LX&|B'''+1Q;;RRALT" 11[111
4[[ A A^*R.((&,JrN7#jn,,/5zz!!qJrN;' #qjjcDFllc tAvo eeG E  k k  #	+ !+%'6!9__S46\\#B!$S)9%9!9!$S)9%9!9!;&0*,,'(   * * * ggc3.>)>#>2:08(*  6 6 ""6***'' <<<<I<<<==T!VD!$ac4ZQ!6t!;!= +[&0*,,'(%   9 9 9 ggcQqS$JqL0$2:08(*  6 6 ""6*** B	 B	B Bxy((  .

3f
----

3f
--- &XXk**r77a<<.0eRUJJ.0$JJ*,dK
(*]:66
),n[99  .4!8q== .OOFSaZT!V,D%(aZT!V$<*5.0l+,	 $ . . . . OOSaZT!V$<$*F*5.0l+,	 $ . . . AID !!%555 0GGDKj07.6&(l#.	  0 0 0 0 GGCgz08.3&(l#.	  0 0 0 !!%666*! 4CJ[4:2:*,,'2	   4 4 4 4 QW_k4<2:*,,'2	   4 4 4 LL #9bW#566 ,0 ,02  Fq?6":#>v#EEBBZ ( {9R=11 2#%	"#52. !
 $&	"a(8#82q!11 ! " :c
SVSV,<c : :*/:",VBZ"8: : : :  RR 03*c : :*/:",VBZ"8: : : BZg--bb4B 0BGRECF9 0&+30 0*2.0 0 0 0 BGSVIu 0&+30 0*2.0 0 0 0  ttEB	J  4
##H---
##F+++
2
	&##F+++
	'$$V,,,
	%""6***
	(((&$w,)?@@@
Aq
5!!!
d3333
##F+++
##F+++
2
	(%%f---
	'$$V,,,
	%""6***
	&&&V'<===
Aq
5!!!
d333Jr   )NNNNNNNNNFNFTr   NNNN)numpyr    r   r   r   r   r   <module>r      s^              ;?8<>B7<)/04*.c c c c c cr   