gL i7<ddlmZddlmZddlmZddlZddlmZddl Zddl Z ddl m Z ddlmZddlmZmZmZer.dd lmZmZdd lmZdd lmZdd lmZdd lmZddl mZddl m!Z!m"Z"ddZ#ddZ$ddZ% d d!dZ& d" d#dZ' d$ d%dZ(d&dZ)d'dZ* d(dZ+d)dZ, d* d+dZ-d,dZ.d-dZ/y).) annotations)ceil) TYPE_CHECKINGN)ticker)find_stack_level) is_list_like) ABCDataFrameABCIndex ABCSeries)IterableSequence)Axes)Axis)Figure)Line2D)Table) DataFrameSeriesc>t|dsy|j S)z+Whether fig has constrained_layout enabled.get_constrained_layoutF)hasattrr)figs g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pandas/plotting/_matplotlib/tools.pydo_adjust_figurer's" 30 1))+ ++c@t|r|j|i|yy)zCCall fig.subplots_adjust unless fig has constrained_layout enabled.N)rsubplots_adjust)rargskwargss rmaybe_adjust_figurer .s$T,V,rc|jD]$}|jd|j|&|j}|t |dyy)Nrightg?)bottom)get_xticklabelsset_horizontalalignment set_rotation get_figurer )axrotlabelrs rformat_date_labelsr+4sW##%  %%g. 3  --/C C,rc t|tr|j}nt|trn t d| |j }| |j }|j}tjj|f|||d|S)Nz&Input data must be DataFrame or Series)cellText rowLabels colLabels) isinstancer to_framer ValueErrorindexcolumnsvalues matplotlibtable)r(datar.r/rr-s rr7r7?s$ "}} D, ' ABBJJ LL {{H    ! !       rc |t|ttfrt|dk7r t d|\}}|dk(r|dkDrt ||z |fx}\}}n7|dk(r|dkDr|t ||z fx}\}}n|dkr|dkr d}t |||z|krt d|d|d||S|d k(ry |d k(rd |fS|d k(r|d fSd dddd} ||S#t $r3d }|dz|kr|d z }|dz|kr|d z |z|k\r ||d z fcYS||fcYSwxYw)Nz)Layout must be a tuple of (rows, columns)rz1At 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:)r0tuplelistlenr2rKeyError)nplotslayout layout_typenrowsncolsmsglayoutsks r _get_layoutrO\s &5$-0CK14DHI I u B;519%)&5.%95$A AF\UE b[UQY%*D%,@$A AF\UE aZEQJECS/ ! 5=6 !UG1UG+NvhW  h  $6{  "{V6:G v  dVm FAdVm EQ;& q1u: a4Ks C D 2D D  D c ddlm} |i}|| jdi|} nt|r|r t |}|$t j dtt|s|r$t j dtt|j|k(r!|jdj} | |fStd|d|j} |dk(r|r| |fS| t |fSt j d tt| jt||| \} } | | z} tj | t" }| j$| | dfi|}|r||d <|r||d <||d<t'd| D]>}|j)}||k\r d|d <d|d <| j$| | |dzfi|}|||<@|| k7r||dD]}|j+dt-|| || | |||r2| dk(r |d}| |fS|j/| | j1}| |fS|j/| | }| |fS)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)) rNz6When 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.)rHrIdtypesharexshareyF)matplotlib.pyplotpyplotfigurer flatten_axeswarningswarn UserWarningrsizeflatr'r2clearrOnpemptyobject add_subplotrangecopy set_visiblehandle_shared_axesreshapesqueeze)naxesrTrUrj subplot_kwr(rHrIfig_kwpltrrJrKrGaxarrax0ikwdsaxess rcreate_subplotsrtsj$  zcjj"6"  !"%! L/1  X/1  ww%ggaj++-Bw 8@.. mmo A:BwL,,, MM4+-   IIKuVMLE5 U]F HHV6 *E #//% 8Z 8C " 8 " 8E!H1f    :!DN!DN S__UE1q5 9D 9a  - "B NN5 ! "ufeUE66J Q;8D 9 ==.668D 9}}UE* 9rc|jD]}|jdt|jtj r#|j t jt|jtjr$|jt jd|jD]}|jd|jjdy)NF)get_majorticklabelsrgr0get_minor_locatorr NullLocatorset_minor_locator AutoLocatorget_minor_formatter NullFormatterset_minor_formatterFormatStrFormatterget_minorticklabels get_label)axists r_remove_labels_from_axisrFs  % % ' e $((*F,>,>? v1134$**,f.B.BC   !:!:2!>?  % % ' e NN  'rcF|dk(r|j}n!|dk(r|j}n td|j|}|j j }|D]6}t j||j j r6yy)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_axesget_shared_y_axesr2 get_siblings get_position get_pointsra array_equal)ax1 compare_axisrs axes_siblings ax1_pointsax2s r_has_externally_shared_axisrVs:s$$&  $$& R  %%c*M!!#..0J~~j#*:*:*<*G*G*IJ rc^|dkDrd}d}d} |dkDr tj|dz|dzftj} |D]#} | j| || || f<%|D]=} | || dz|| fs|s t | ds)t | j ? |dkDr5|D]/} | | r |s t | dst | j1yyy#t$r:d} |D]/} | | r |s t | dst | j 1Y~wxYw) Nr>cJ|jjjSN)get_subplotspecrowspanstartr<s rz$handle_shared_axes..A--/77==rcJ|jjjSr)rcolspanrrs rrz$handle_shared_axes..rrc>|jjSr)r is_first_colrs rrz$handle_shared_axes..s!2!2!4!A!A!CrrRr<c>|jjSr)r is_last_rowrs rrz$handle_shared_axes..s(9(9(;(G(G(Irr) razerosbool_ get_visiblerrxaxis IndexErroryaxis) rorGrkrJrKrTrUrow_numcol_numrrHr(rs rrhrhsTz==C 19 ;519eai"8IHB79~~7GF72; 34H ;B"'"+/72;">? !rcLddlm}t|D]}|!|j|j ||!|j|j ||!|j|j ||o|j|j ||S)Nr)fontsize)rotation)rWrXrZsetpr$get_yticklabels)rs xlabelsizexrot ylabelsizeyrotrnr(s rset_ticks_propsrs$4 :  ! HHR'')JH ?   HHR'')DH 9  ! HHR'')JH ?   HHR'')DH 9: Krc|j}t|dr||jjz }t|dr||jjz }|S)Nright_axleft_ax) get_linesrrr)r(liness r get_all_linesrsT LLNEr: &&((r9 %%'' Lrctjtj }}|D]R}|jd}ttj||}t tj ||}T||fS)NF)orig)rainf get_xdataminnanminmaxnanmax)rleftr"liner<s rget_xlimrsh&&266'%D) NNN &299Q<&BIIaL%() ;r)rrreturnbool)rrrNone)r(rrr)NN)r8zDataFrame | Seriesrr)Nbox)rGintrHztuple[int, int] | NonerIstrrztuple[int, int])FFTNNNr) rkrrTrrUrrjrrIr)rrrr)rrrrrr)rozIterable[Axes]rGrrkrrJrrKrrTrrUrrr)rsAxes | Sequence[Axes]rz np.ndarray)NNNN)rsrr int | Nonerr)r(rrz list[Line2D])rzIterable[Line2D]rztuple[float, float])0 __future__rmathrtypingrr[r6rmatplotlib.tablenumpyrapandas.util._exceptionsrpandas.core.dtypes.commonrpandas.core.dtypes.genericr r r collections.abcr r matplotlib.axesrmatplotlib.axisrmatplotlib.figurermatplotlib.linesrrpandasrrrr r+r7rOrtrrrhrZrrrrVrrrs" 42  %$('& ,- -=A  >&*, , ",, ,h u u u u uup ( /d27 27 27 27  27  27  27 27 27j" !   * r