
    !gE                     .    d dl ZddlmZ 	 	 	 	 	 	 	 ddZy)    N   )utilsc                    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kD  }|dkD  r|nd}||z  }|j                  d       |j                  d       |%t        t        |            }|j                          n|}|	%t        t        |            }|j                          n|	}i }t        |      D ]=  }|||   |vr|	||   |	vr||   ||   f} | |vrg || <   ||    j                  |       ? |j!                         j#                  |j$                  j'                               }!|!j(                  |!j*                  }#}"t        |      }$d	\  }%}&|r'|j-                  |j.                  |j0                        }'n&|j-                  |j0                  |j.                        }'||#z  }(|r|&|%z
  ||(z  z
  t3        |$      z  })n|&|%z
  t3        |$      z  })||}*n$t        t        |            }*|*j                          |r|*ddd
   }*t        |*      }+|+dkD  r|)dt3        |+      dz
  z  z  },nd},|*D -ci c]  }-|-|*j5                  |-       }.}-g d}/||*D -ci c]  }-|-i  }}-t        |+      D ]K  }0|*|0   }1d||1   vr|/|0t        |/      z     ||1   d<   d||1   vrd||1   d<   d||1   vs=|,dk(  rdnd||1   d<   M ||*D -ci c]  }-|-i  }}-t        |+      D ]-  }0|*|0   }1d||1   vrd||1   d<   d||1   vs|,dkD  rdnd||1   d<   / |r|dk(  r|&|)dz  z
  n|&}2n|%|)dz  z   }2t               }3g }4|D ]7  }5|r"|r|5|d   k(  r|2|)dz  z   n|2}6|j7                  d	|6|6f|2d|(z  z
  |2d|(z  z
  fd|j0                  d       |j9                  d|2d|(z  z
  |5dd|j0                        }7|7j;                  d       |2|(z  }2nt        |D 8cg c]  }8|8d   |5k(  s|8 c}8      }9|j7                  |2|)dz  z
  dz   |2|9dz
  |)z  z   |)dz  z   dz
  fd d!d|j0                  dd"       |j9                  |2|9dz
  |)z  dz  z   d#|5dd$|j0                        }7|7j;                  d       d}:|D ]  };|5|;f|vr|r|j=                  |2d%       n|j?                  |2d%       |/|;jA                  |      }<t        |<      dk\  r|<d   |<d   }>}=n	|;d}>}=n|;d}>}=| ||=      }=| ||>      }>|rw|:dz  dk(  ro|r>|j7                  d	|2|)dz  z
  |2|)dz  z
  f|2|)dz  z   |2|)dz  z   fd&|j0                  d       n/|j7                  |2|)dz  z
  |2|)dz  z   fd'd(d&|j0                  d       |:dz  }:|jC                         d)v rM|r&|j9                  d*|"z  |2|=d+d|j0                  d,-       n%|j9                  |2d*|#z  |=dd.|j0                  d,-       |jC                         d/v rU|>S|r)|j9                  dd0|"z  z   |2|>d1d|j0                  d,-       n(|j9                  |2dd0|#z  z   |>dd$|j0                  d,-       |4j                  |2       tE        ||5|;f         D ]  \  }?}@d}A|
r|) d2z  |.|@      |,z  z   }A| @   }B|t	        jF                  |@         rB|@   z
  |B||@   z   }D}CnB|@   d   z
  |B||@   d   z   }D}C|r( |jH                  CDg|2Az   |2|Az   gd3fd4|'i||@       n' |jH                  |2Az   |2|Az   gCDgd3fd4|'i||@       |@   }E|E|3vrEnd}F|3jK                  E       |r! |jH                  Bg|2Az   gfd5|'Fd6|E     |jH                  |2Az   gBgfd5|'Fd6|E     |r|2|)z  }2|2|)z  }2
 : |r|jL                  jO                  d$       |jP                  jO                  d7       |jS                  g        |jT                  d1   jW                  d7       |jT                  d+   jW                  d7       |jT                  d.   jW                  d7       |jT                  d$   jY                  d8d*|#z  f       |j[                  dd       |jP                  j]                  |4       |j_                  dd9       |S |jP                  jO                  d1       |jL                  jO                  d7       |ja                  g        |jT                  d$   jW                  d7       |jT                  d+   jW                  d7       |jT                  d.   jW                  d7       |jT                  d1   jY                  d8d*|"z  f       |jc                  dd       |jL                  j]                  |4       |j_                  dd:       |S c c}-w c c}-w c c}-w c c}8w );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                 4    | d S t        j                  |       S )N)npasarray)xs    Z/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/statsmodels/graphics/dotplots.py<lambda>zdot_plot.<locals>.<lambda>   s     

1     g      ?FTr   g{Gz?)r   r   g      @g        )rgbykpurpleorangecolormarkeroms
      grey	linewidth      gffffff?darkgrey)r   	transformzordergffffff?center)horizontalalignmentverticalalignmentr    boldg{Gz?))\(?r&   )(\?r'   )r   r    r!   clip_ongRQ?bottom)r   	lightgrey)r   r   )r   r   )leftbothgright	monospace)r#   r$   r    familytop)r-   r,   g?r+      -r    None)lsr    labelnoneaxes)scaleytight)scalexr9   )2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index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)G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axr<   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nrowsr)   r0   transtitle_space_axesdposstyle_codesnvalstackdr	   style_codes_mapcolorsjscposlabeledticksk0y0txtr   mjrowk1us
left_labelright_labeljijpyoptlcbucbslsllsG                                                                          r
   dot_plotr      s3   n /!!"%GC ZZFEO	*IE"Ex(HV$F [F }		&! 88F# ~&!  HE C&' e##		$"#ai$qyea .; NN4NN4c(m$c%j! I6]  $!M)I!eAhj&@qk58$YIbM"Q  !--$$&(Djj$++GF 	NE
 KFC44R\\57\\C 44R\\57\\C +W4 f{+;;;%L fe, "3v;' !$B$'{DaxeDk!m,- 9DD1q+++A..DOD ;F'23!2334[ >^,r**(.q3v;(?LW%<++),LX&|B''+1Q;RALT"> %01ae1
14[ A^*R.(&,JrN7#jn,/5z!qJrN;'A #qjcDFlc tAvo eG E  k %'6!9_S46\#B!$S)9%9!9!$S)9%9!9!;&0*,,,'(   * ggc3.>)>#>2:08(*  6 ""6*'' I<q1<=T!VD!$ac4ZQ!6t!;!= +[&0*,,,'(%   9 ggcQqS$JqL0$2:08(*  6 ""6* B	B Bxy( 

3f
-

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