rL iTdZddlZddlZddlZddlZddlZddl m Z ddl m Z ejeZGddZej$ZdZddZy) a A layoutgrid is a nrows by ncols set of boxes, meant to be used by `._constrained_layout`, each box is analogous to a subplotspec element of a gridspec. Each box is defined by left[ncols], right[ncols], bottom[nrows] and top[nrows], and by two editable margins for each side. The main margin gets its value set by the size of ticklabels, titles, etc on each Axes that is in the figure. The outer margin is the padding around the Axes, and space for any colorbars. The "inner" widths and heights of these boxes are then constrained to be the same (relative the values of `width_ratios[ncols]` and `height_ratios[nrows]`). The layoutgrid is then constrained to be contained within a parent layoutgrid, its column(s) and row(s) specified when it is created. N)BboxceZdZdZ ddZdZdZdZdZdd Z d Z d Z d Z dd Z dZdZdZdZddZddZddZddZddZddZddZdZy) LayoutGridzG Analogous to a gridspec, and contained in another LayoutGrid. Nrrc tj} ||_||_|t z|_t |tr |j d|j |_||_||_ tj| |_ | tj||_ tj| |_| tj||_|j dz} t |tstj|_n$|j"|g||j |_tj$||ft&|_tj$||ft&|_i|_i|_dD]$} tj0||j.| <&|j }t3|Dcgc]}| | d|dc}|_t3|Dcgc]}| | d|dc}|_dD]i} t3|Dcgc]}| | d| d |dc}|j,| <t3|D]$}|j9|j,| |d &kd D]L} tj$|t&|j,| <tj0||j.| <Nt3|Dcgc]}| | d |dc}|_t3|Dcgc]}| | d |dc}|_d D]i} t3|Dcgc]}| | d| d |dc}|j,| <t3|D]$}|j9|j,| |d &k|j?|jA|||_!||_"ycc}wcc}wcc}wcc}wcc}wcc}w)N._)dtype)leftrightleftcbrightcbzlefts[]zrights[zmargins[z][strong)bottomtopbottomcbtopcbzbottoms[ztops[)#kiwiVariable parent_pos parent_innerseq_idname isinstancernrowsncolsnp atleast_1d height_ratiosones width_ratiosSolversolver add_childemptyobjectartistschildrenmargins margin_valszerosrangeleftsrightsaddEditVariablebottomstops reset_marginsadd_constraintsh_padw_pad)selfparentrrrrrr5r6r"r rsntodosolis \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/_layoutgrid.py__init__zLayoutGrid.__init__$s==$(68O fj )!;;-q 4DI  ]]=9  !#D MM,7   "D  YY_&*-++-DK F  T /J / --DKxxf= %v>  : 5D&(XXe_D  T " 5 kk;@<Hah"VA3a01H =B5\Jx2$gaS 23J : ED+0<"9&'#+bT$r!A+F"G"9DLL 5\ E##DLL$6q$98D E E ; 5D!#5!@DLL %'XXe_D  T " 5@EU|L!B4xs!!45L 9>uFAXE!A./F : ED+0<"9&'#+bT$r!A+F"G"9DLL 5\ E##DLL$6q$98D E E  V$  5IJ"9MF"9s$ O6O %OO O8Ocd|jdd|jd|jd}t|jD].}t|jD]}||d|d|j|j dd |j |j dd |j|j dd |j|j dd |jd |j dd|jd|j dd|jd|j dd|jd|j ddz }1|S)Nz LayoutBox: 25s xz, z, z: Lz1.3fz, Bz, Rz, Tz, MLr z, MRr z, MBrz, MTrz, ) rrrr-r.valuer1r/r2r*)r7strr<js r=__repr__zLayoutGrid.__repr__isDIIc?!DJJ//1$7899Q<--/56 LL0399;DAB LL1!4::DLL$9!$<<LL+A./JJqMDLL$8$;;LL*1-..B  : ))!j.9 : :tzz" :A))A,$,,q/199Q<$,,u"5a"88LL)!,-LLOdll8&>**Q-4'++b/U*))A,#%,,r"f, .B  6A KK % %a*n 5 6rGc|jd|jddz |jddz }||jdz |jddz |jddz }||jdz }t d|j D]}|j||jd|z |jd|z }||j|z |jd|z |jd|z }|||j|zk(}|j j|dz|j|dz |j|k(}|j j|dz|jd|jddz |jd dz }||jdz |jd dz |jd dz }||jdz }t d|jD]}|j||jd|z |jd |z }||j|z |jd |z |jd |z }|||j|zk(}|j j|dz|j|dz |j|k(}|j j|dzy) Nrr rr r rZrrrrr) r/r*r.r"r-rr$rQr2r1r r)r7ww0r<rShh0s r=rNzLayoutGrid.grid_constraintss [[^dll73A6 6 \\) $Q '( A f!5a!8 8 \\( #A &' ""1% %q$**% 4AQ$,,w"7"::i(+,ATZZ]"T\\&%9!%<<h'*+Ab4,,Q///A KK % %a(l 3QU#tzz!}4A KK % %a(l 3 4 IIaL4<<.q1 1DLL4I!4L L a 4<<#9!#< < \\* %a () ##A& &q$**% 4A1 U 3A 66g&q)*AT\\!_$t||H'=a'@@j)!,-Ab4--a000A KK % %a(l 3a!e$ ! 4A KK % %a(l 3 4rGc|jj|j|||||j||<y)a Change the size of the margin for one cell. Parameters ---------- todo : string (one of 'left', 'right', 'bottom', 'top') margin to alter. size : float Size of the margin. If it is larger than the existing minimum it updates the margin size. Fraction of figure size. cell : int Cell column or row to edit. N)r$ suggestValuer*r+r7r:sizecells r= edit_marginzLayoutGrid.edit_margins;   d!3D!94@'+t$rGcV||j||kDr|j|||yy)a Change the minimum size of the margin for one cell. Parameters ---------- todo : string (one of 'left', 'right', 'bottom', 'top') margin to alter. size : float Minimum size of the margin . If it is larger than the existing minimum it updates the margin size. Fraction of figure size. cell : int Cell column or row to edit. N)r+rhres r=edit_margin_minzLayoutGrid.edit_margin_min s3$ $""4(. .   T4 . /rGcvtt|j|D]}|j|||y)a1 Change the size of all the margin of all the cells in the layout grid. Parameters ---------- todo : string (one of 'left', 'right', 'bottom', 'top') margin to alter. size : float Size to set the margins. Fraction of figure size. N)r-lenr+rhr7r:rfr<s r=rIzLayoutGrid.edit_margins"s:s4++D123 ,A   T4 + ,rGcvtt|j|D]}|j|||y)a Change the minimum size of all the margin of all the cells in the layout grid. Parameters ---------- todo : {'left', 'right', 'bottom', 'top'} The margin to alter. size : float Minimum size of the margin. If it is larger than the existing minimum it updates the margin size. Fraction of figure size. N)r-rlr+rjrms r=edit_all_margins_minzLayoutGrid.edit_all_margins_min2s: s4++D123 0A  tQ / 0rGc|jd|d|jj|jd|d|jj|jd|d|jjdz |jd|d|jjdz |jd|d|jj|jd|d|jj|jd|d|jjdz |jd |d |jjdz y ) a< Edit all four margin minimums in one statement. Parameters ---------- margin : dict size of margins in a dict with keys 'left', 'right', 'bottom', 'top' ss : SubplotSpec defines the subplotspec these margins should be applied to r r r rZrrrrrN)rjcolspanstartstoprowspan)r7marginsss r=edit_outer_margin_minsz!LayoutGrid.edit_outer_margin_minsEs VVF^RZZ5E5EF Xvh'79I9IJ WfWorzz7JK Yy(92::??Q;NO UF5M2::3C3CD WfWorzz7G7GH Xvh'719LM Z );ZZ__q0 2rGc&|j||S)z"Return the margin at this position)r+)r7r:cols r= get_marginszLayoutGrid.get_margins^s%c**rGcztj|}tj|}tj|j|dj |j |dj |j|dj |j|dj }|S)z Return the outer bounding box of the subplot specs given by rows and cols. rows and cols can be spans. rrX) rrr from_extentsr.rCr1r/r2r7r\r]bboxs r=get_outer_bboxzLayoutGrid.get_outer_bboxbs }}T"}}T"  JJtAw  % % ' LLb " ( ( * KKR ! ' ' ) IId1g  $ $ & (  rGc tj|}tj|}tj|j|dj |j d|dj z|j d|dj z|j|dj |j d|dj z|j d|dj z|j|dj |j d|dj z |j d|dj z |j|dj |j d |dj z |j d |dj z }|S) z Return the inner bounding box of the subplot specs given by rows and cols. rows and cols can be spans. rr r rXrrr rrr rrrr|r.rCr*r1r/r2r}s r=get_inner_bboxzLayoutGrid.get_inner_bboxqs }}T"}}T"  ZZQ & & ( V$T!W-3356 X&tAw/5578\\$r( # ) ) + X&tBx06689 Z(b288:;[[b " ( ( * W%d2h/5578 Y'R1779:YYtAw  % % ' U#DG,2245 W%d1g.4467   rGc tj|}tj|}tj|j|dj |j d|dj z|j|dj |j d|dj z|j|dj |j d|dj z |j|dj |j d|dj z }|S)zj Return the bounding box that includes the decorations but, *not* the colorbar... rr rXrrrrr}s r=get_bbox_for_cbzLayoutGrid.get_bbox_for_cbs' }}T"}}T"  ZZQ & & ( X&tAw/5578 \\$r( # ) ) + Z(b288:; [[b " ( ( * Y'R1779: YYtAw  % % ' W%d1g.4467   rGcRtj|}tj|}tj|j|dj |j d|dj z|j|dj |j|dj |j d|dj z|j d|dj z|j|dj }|S) Return the left margin bounding box of the subplot specs given by rows and cols. rows and cols can be spans. rr rXr ) rrrr|r.rCr*r1r2r}s r=get_left_margin_bboxzLayoutGrid.get_left_margin_bboxs }}T"}}T"  ZZQ & & ( X&tAw/5578 \\$r( # ) ) + ZZQ & & ( X&tAw/5578 V$T!W-3356YYtAw  % % '* rGc Rtj|}tj|}tj|j|dj |j |dj |jd|dj z|j|dj |j |dj |jd|dj z|jd|dj z}|S)rrrXrr) rrrr|r.rCr1r*r/r}s r=get_bottom_margin_bboxz!LayoutGrid.get_bottom_margin_bboxs }}T"}}T"  ZZQ & & ( \\$r( # ) ) + \\* %d2h / 5 5 78 [[b " ( ( * \\$r( # ) ) + X&tBx06689 \\* %d2h / 5 5 78  rGcRtj|}tj|}tj|j|dj |j d|dj z |j d|dj z |j|dj |j|dj |j d|dj z |j|dj }|S)rrXr rr) rrrr|r/rCr*r1r2r}s r=get_right_margin_bboxz LayoutGrid.get_right_margin_bboxs }}T"}}T"  [[b " ( ( * W%d2h/5578 Y'R1779:\\$r( # ) ) + [[b " ( ( * Y'R1779: YYtAw  % % '* rGc Rtj|}tj|}tj|j|dj |j |dj |jd|dj z |j|dj |j |dj |jd|dj z |jd|dj z }|S)rrrrXr) rrrr|r.rCr2r*r/r}s r=get_top_margin_bboxzLayoutGrid.get_top_margin_bboxs }}T"}}T"  ZZQ & & ( YYtAw  % % ' W%d1g.4467 [[b " ( ( * YYtAw  % % ' W%d1g.4467 U#DG,2245 7 rGc8|jjy)zR Update the variables for the solver attached to this layoutgrid. N)r$updateVariables)r7s r=update_variableszLayoutGrid.update_variabless ##%rG) NrFrZrZNNNN)r)__name__ __module__ __qualname____doc__r>rFr3r4rLr%rMrNrhrjrIrorwrzrrrrrrrrrGr=rrs06=>6:#CJ ) :2J&6P%4T,&/*, 0&22+ 0($&$$&rGrc&dttzS)z5Generate a short sequential id for layoutbox objects.z%06d)next_layoutboxobjnumrrGr=rrs D)* **rGc^|$|jj|}||}tjdj d}||}t |j D]}t |jD]z}|j||}|jtj|j|j|jdddd|jd |j!||} |jtj| j| j| jd |d |jd |j#||} |jtj| j| j| jdd dgd|jd  |j%||} |jtj| j| j| jdd dgd|jd  |j'||} |jtj| j| j| jdd dgd|jd  |j)||} |jtj| j| j| jdd dgd|jd  }|j*j,D]} | t/|| |dzy)z(Simple plotting to show where boxes are.Nzaxes.prop_cyclecolor)r\r]rZz0.7皙?) linewidth edgecolor facecoloralpha transformzorderrYnone)rrrrrr)?ffffff?r)rrrrrr)rrr)rrr)rrr)level)get_layout_engineexecutemplrcParamsby_keyr-rrr add_artistmpatches Rectanglep0widthheight transFigurerrrrrr)flat plot_children) figlgr _layoutgridscolorsryr<rEbbbbichs r=rrs z,,.66s; #  \\+ , 3 3 5g >F -C 288_%Jrxx$ JA"""2B NN""255"((BII-2e),*,. / ###3C NN""366399cjjA-0F-0__RI J ))qq)9C NN""366399cjjA-33-<-0__RI J ***:C NN""366399cjjA-33-<-0__RI J +++;C NN""366399cjjA-33-<-0__RI J ((aa(8C NN""366399cjjA-33-<-0__RI JA$ J%JLkk2 > #rq 12rG)Nr)r itertools kiwisolverrloggingnumpyr matplotlibrmatplotlib.patchespatchesrmatplotlib.transformsr getLoggerr_logrcountrrrrrGr=rs[$%&w"K&K&Z#9??$+ /2rG