
    *g<                       d dl mZ d dlmZ d dlmZ d dlZd dlmZ d dl	Zd dl
Zd dlmZ d dlmZ d dlmZmZmZ er.d d	lmZmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dl	mZ d dl m!Z!m"Z" ddZ#ddZ$ddZ%	 d 	 	 	 d!dZ&	 	 d"	 	 	 	 	 	 	 d#dZ'	 	 	 	 	 	 	 d$	 	 	 	 	 	 	 	 	 d%dZ(d&dZ)d'dZ*	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(dZ+d)dZ,	 	 	 	 d*	 	 	 	 	 d+dZ-d,dZ.d-dZ/y).    )annotations)ceil)TYPE_CHECKINGN)ticker)find_stack_level)is_list_like)ABCDataFrameABCIndex	ABCSeries)IterableSequence)Axes)Axis)Figure)Line2D)Table)	DataFrameSeriesc                >    t        | d      sy| j                          S )z+Whether fig has constrained_layout enabled.get_constrained_layoutF)hasattrr   )figs    k/var/www/html/articles-backend/trend/venv/lib/python3.12/site-packages/pandas/plotting/_matplotlib/tools.pydo_adjust_figurer   '   s"    301))+++    c                @    t        |       r | j                  |i | yy)zCCall fig.subplots_adjust unless fig has constrained_layout enabled.N)r   subplots_adjust)r   argskwargss      r   maybe_adjust_figurer    .   s$    T,V, r   c                    | j                         D ]$  }|j                  d       |j                  |       & | j                         }|t	        |d       y y )Nrightg?)bottom)get_xticklabelsset_horizontalalignmentset_rotation
get_figurer    )axrotlabelr   s       r   format_date_labelsr+   4   sW    ##%  %%g.3  --/C
C, r   c                   t        |t              r|j                         }nt        |t              rnt	        d      ||j
                  }||j                  }|j                  }t        j                  j                  | f|||d|S )Nz&Input data must be DataFrame or Series)cellText	rowLabels	colLabels)

isinstancer   to_framer	   
ValueErrorindexcolumnsvalues
matplotlibtable)r(   datar.   r/   r   r-   s         r   r7   r7   ?   s     $	"}}	D,	'ABBJJ	LL	{{H !!
	
  r   c                    |t        |t        t        f      rt        |      dk7  rt	        d      |\  }}|dk(  r|dkD  rt        | |z        |fx}\  }}n7|dk(  r|dkD  r|t        | |z        fx}\  }}n|dk  r|dk  rd}t	        |      ||z  | k  rt	        d| d| d|        |S |d	k(  ry
|dk(  rd| fS |dk(  r| dfS d
dddd}	 ||    S # t        $ r3 d}|dz  | k  r|dz  }|dz  | k  r|dz
  |z  | k\  r	||dz
  fcY S ||fcY S w xY w)N   z)Layout must be a tuple of (rows, columns)r   z1At least one dimension of layout must be positivez
Layout of xz# must be larger than required size single)   r>   
horizontalr>   vertical)r>   r:   )r:   r:   )r>   r:         )r0   tuplelistlenr2   r   KeyError)nplotslayoutlayout_typenrowsncolsmsglayoutsks           r   _get_layoutrO   \   s   
 &5$-0CK14DHIIuB;519%)&5.%95$AAF\UEb[UQY%*D%,@$AAF\UEaZEQJECS/!5=6!UG1UG+NvhW  h		$6{	
	"{V6:G
v dVmFA dVm EQ;& q1u:a4Ks   C  D2DDDc           	        ddl m}	 |i }| |	j                  di |}
nt        |      r|rt	        |      }|$t        j                  dt        t                      |s|r$t        j                  dt        t                      |j                  | k(  r!|j                  d   j                         }
|
|fS t        d|  d      |j                         }
| dk(  r|r|
|fS |
t	        |      fS t        j                  d	t        t                      |
j                          t        | ||
      \  }}||z  }t        j                   |t"              } |
j$                  ||dfi |}|r||d<   |r||d<   ||d<   t'        d|      D ]>  }|j)                         }|| k\  r
d|d<   d|d<    |
j$                  |||dz   fi |}|||<   @ | |k7  r|| d D ]  }|j+                  d        t-        ||| ||||       |r2|dk(  r	|d   }|
|fS |j/                  ||      j1                         }|
|fS |j/                  ||      }|
|fS )a	  
    Create a figure with a set of subplots already made.

    This utility wrapper makes it convenient to create common layouts of
    subplots, including the enclosing figure object, in a single call.

    Parameters
    ----------
    naxes : int
      Number of required axes. Exceeded axes are set invisible. Default is
      nrows * ncols.

    sharex : bool
      If True, the X axis will be shared amongst all subplots.

    sharey : bool
      If True, the Y axis will be shared amongst all subplots.

    squeeze : bool

      If True, extra dimensions are squeezed out from the returned axis object:
        - if only one subplot is constructed (nrows=ncols=1), the resulting
        single Axis object is returned as a scalar.
        - for Nx1 or 1xN subplots, the returned object is a 1-d numpy object
        array of Axis objects are returned as numpy 1-d arrays.
        - for NxM subplots with N>1 and M>1 are returned as a 2d array.

      If False, no squeezing is done: the returned axis object is always
      a 2-d array containing Axis instances, even if it ends up being 1x1.

    subplot_kw : dict
      Dict with keywords passed to the add_subplot() call used to create each
      subplots.

    ax : Matplotlib axis object, optional

    layout : tuple
      Number of rows and columns of the subplot grid.
      If not specified, calculated from naxes and layout_type

    layout_type : {'box', 'horizontal', 'vertical'}, default 'box'
      Specify how to layout the subplot grid.

    fig_kw : Other keyword arguments to be passed to the figure() call.
        Note that all keywords not recognized above will be
        automatically included here.

    Returns
    -------
    fig, ax : tuple
      - fig is the Matplotlib Figure object
      - ax can be either a single axis object or an array of axis objects if
      more than one subplot was created.  The dimensions of the resulting array
      can be controlled with the squeeze keyword, see above.

    Examples
    --------
    x = np.linspace(0, 2*np.pi, 400)
    y = np.sin(x**2)

    # Just a figure and one subplot
    f, ax = plt.subplots()
    ax.plot(x, y)
    ax.set_title('Simple plot')

    # Two subplots, unpack the output array immediately
    f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
    ax1.plot(x, y)
    ax1.set_title('Sharing Y axis')
    ax2.scatter(x, y)

    # Four polar axes
    plt.subplots(2, 2, subplot_kw=dict(polar=True))
    r   Nz6When passing multiple axes, layout keyword is ignored.)
stacklevelzoWhen passing multiple axes, sharex and sharey are ignored. These settings must be specified when creating axes.z"The number of passed axes must be z, the same as the output plotr>   zTTo output multiple subplots, the figure containing the passed axes is being cleared.)rH   rI   dtypesharexshareyF )matplotlib.pyplotpyplotfigurer   flatten_axeswarningswarnUserWarningr   sizeflatr'   r2   clearrO   npemptyobjectadd_subplotrangecopyset_visiblehandle_shared_axesreshapesqueeze)naxesrT   rU   rj   
subplot_kwr(   rH   rI   fig_kwpltr   rJ   rK   rG   axarrax0ikwdsaxess                      r   create_subplotsrt      s   j $
	zcjj"6"!"%!L/1
 X/1	 ww%ggaj++-Bw 8 @. . 
 mmoA:BwL,,,MM4+-	 IIKuVMLE5U]F HHV6*E #//%
8Z
8C"
8"
8E!H 1f 	  :!DN!DNS__UE1q59D9a	 - 	"BNN5!	" ufeUE66J Q;8D 9 ==.668D
 9 }}UE*9r   c                   | j                         D ]  }|j                  d        t        | j                         t        j
                        r#| j                  t	        j                                t        | j                         t        j                        r$| j                  t	        j                  d             | j                         D ]  }|j                  d        | j                         j                  d       y )NF )get_majorticklabelsrg   r0   get_minor_locatorr   NullLocatorset_minor_locatorAutoLocatorget_minor_formatterNullFormatterset_minor_formatterFormatStrFormatterget_minorticklabels	get_label)axists     r   _remove_labels_from_axisr   F  s    %%' 	e
 $((*F,>,>?v1134$**,f.B.BC  !:!:2!>?%%' 	e 	NN  'r   c                F   |dk(  r| j                         }n!|dk(  r| j                         }nt        d      |j                  |       }| j	                         j                         }|D ]6  }t        j                  ||j	                         j                               r6 y y)aA  
    Return whether an axis is externally shared.

    Parameters
    ----------
    ax1 : matplotlib.axes.Axes
        Axis to query.
    compare_axis : str
        `"x"` or `"y"` according to whether the X-axis or Y-axis is being
        compared.

    Returns
    -------
    bool
        `True` if the axis is externally shared. Otherwise `False`.

    Notes
    -----
    If two axes with different positions are sharing an axis, they can be
    referred to as *externally* sharing the common axis.

    If two axes sharing an axis also have the same position, they can be
    referred to as *internally* sharing the common axis (a.k.a twinning).

    _handle_shared_axes() is only interested in axes externally sharing an
    axis, regardless of whether either of the axes is also internally sharing
    with a third axis.
    r<   yzD_has_externally_shared_axis() needs 'x' or 'y' as a second parameterTF)get_shared_x_axesget_shared_y_axesr2   get_siblingsget_position
get_pointsra   array_equal)ax1compare_axisrs   axes_siblings
ax1_pointsax2s         r   _has_externally_shared_axisr   V  s    : s$$&		$$&R
 	
 %%c*M !!#..0J ~~j#*:*:*<*G*G*IJ r   c                ^   |dkD  rd }d }d }	|dkD  r	 t        j                  |dz   |dz   ft         j                        }
| D ]#  }|j                         |
 ||       ||      f<   % | D ]=  }|
 ||      dz    ||      f   s|st	        |d      s)t        |j                         ? 	 |dkD  r5| D ]/  } |	|      r|st	        |d      st        |j                         1 y y y # t        $ r: d }| D ]/  } ||      r|st	        |d      st        |j                         1 Y ~w xY w)	Nr>   c                J    | j                         j                  j                  S N)get_subplotspecrowspanstartr<   s    r   <lambda>z$handle_shared_axes.<locals>.<lambda>      A--/77== r   c                J    | j                         j                  j                  S r   )r   colspanr   r   s    r   r   z$handle_shared_axes.<locals>.<lambda>  r   r   c                >    | j                         j                         S r   )r   is_first_colr   s    r   r   z$handle_shared_axes.<locals>.<lambda>  s    !2!2!4!A!A!C r   rR   r<   c                >    | j                         j                         S r   )r   is_last_rowr   s    r   r   z$handle_shared_axes.<locals>.<lambda>  s    (9(9(;(G(G(I r   r   )	ra   zerosbool_get_visibler   r   xaxis
IndexErroryaxis)ro   rG   rk   rJ   rK   rT   rU   row_numcol_numr   rH   r(   r   s                r   rh   rh     sT    z==C19; 519eai"8I HB79~~7GF72;34H   ;B "'"+/72;">? !<R!E0:;& 19 7  #8SA,RXX67 C .  ; J ;B"2 !<R!E0:	;	;s   A?C) C) )(D,D,+D,c                    t        |       st        j                  | g      S t        | t        j                  t
        f      r#t        j                  |       j                         S t        j                  |       S r   )r   ra   arrayr0   ndarrayr
   asarrayravel)rs   s    r   rZ   rZ     sT    xx	D2::x0	1zz$%%''88D>r   c                L   dd l m} t        |       D ]  }|!|j                  |j	                         |       |!|j                  |j	                         |       |!|j                  |j                         |       |o|j                  |j                         |        | S )Nr   )fontsize)rotation)rW   rX   rZ   setpr$   get_yticklabels)rs   
xlabelsizexrot
ylabelsizeyrotrn   r(   s          r   set_ticks_propsr     s     $4  :!HHR'')JH?HHR'')DH9!HHR'')JH?HHR'')DH9: Kr   c                    | j                         }t        | d      r|| j                  j                         z  }t        | d      r|| j                  j                         z  }|S )Nright_axleft_ax)	get_linesr   r   r   )r(   liness     r   get_all_linesr     sT    LLNEr:&&((r9%%''Lr   c                    t         j                  t         j                   }}| D ]R  }|j                  d      }t        t        j                  |      |      }t        t        j                  |      |      }T ||fS )NF)orig)ra   inf	get_xdataminnanminmaxnanmax)r   leftr"   liner<   s        r   get_xlimr     sh    &&266'%D )NNN&299Q<&BIIaL%() ;r   )r   r   returnbool)r   r   r   None)r(   r   r   r   )NN)r8   zDataFrame | Seriesr   r   )Nbox)rG   intrH   ztuple[int, int] | NonerI   strr   ztuple[int, int])FFTNNNr   )
rk   r   rT   r   rU   r   rj   r   rI   r   )r   r   r   r   )r   r   r   r   r   r   )ro   zIterable[Axes]rG   r   rk   r   rJ   r   rK   r   rT   r   rU   r   r   r   )rs   Axes | Sequence[Axes]r   z
np.ndarray)NNNN)rs   r   r   
int | Noner   r   )r(   r   r   zlist[Line2D])r   zIterable[Line2D]r   ztuple[float, float])0
__future__r   mathr   typingr   r[   r6   r   matplotlib.tablenumpyra   pandas.util._exceptionsr   pandas.core.dtypes.commonr   pandas.core.dtypes.genericr	   r
   r   collections.abcr   r   matplotlib.axesr   matplotlib.axisr   matplotlib.figurer   matplotlib.linesr   r   pandasr   r   r   r    r+   r7   rO   rt   r   r   rh   rZ   r   r   r   rV   r   r   <module>r      s   "        4 2  
 %$('&,-- =A 
> &*,,", , 	,h uuu u 	u up( /d272727 27 	27
 27 27 27 
27j "	!	
 	*	r   