rL i^ ddlZddlZddlZddlZddlZddlmZddl m Z ddl m ZddlmZmZej"j%dgZd[dZd\dZedgd d Zed gd d Zed gd dZedgd dZedgd dZedgd dZdZdZedgd dZedgd dZedgdej@dk(rdnddZ!ed gd d!Z"ed"gd d#Z#ed$gd d%Z$ed&gd d'Z%ed(gd d)Z&ed*gd d+Z'ed,gd d-Z(ed.gd d/Z)d0Z*d1Z+d2Z,d3Z-d4Z.d5Z/ed6gd7d8d9Z0d:Z1d;Z2edgd d?Z4d@Z5edAgd7ddBdCiDdEZ6edFgd7ddBejndGdgdHdIggiDdJZ8dKZ9dLZ:dMZ;dNZdQZ?dRZ@ej"jdSdTdUid7fdVdid7fgdWZBdXZCdYZDdZZEy)]N)image_comparison)gridspectickertext_placeholdersc |jddg|jd|s:|jd||jd||j d|y|j g|j gy) Nnbinsx-labelfontsizey-labelTitle)plotlocator_params set_xlabel set_ylabel set_titleset_xticklabelsset_yticklabels)axrnodecs m/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/tests/test_constrainedlayout.py example_plotrsqGGQFOA  i( 3 i( 3 Wx 0 2 2c d\}}tjtdd|z|tdd|z|f\}}d|dz z |dzz|dzztj|dz |dzz z}|j |||ddddfd d d d }|j d||j d||jd||S)N)333333?rr r@r RdBu_rg?T)cmapvminvmax rasterizedr rrr)npmgridsliceexp pcolormeshrrr)rrdxdyyxzpcms rexample_pcolorr5s FB 88E"a"fb)"a"fb)* +DAq QVa1f qAv %a!q&0@)AAA --1aSbSks#'  )CMM)hM/MM)hM/LL8L, Jrzconstrained_layout1.pngmpl20)stylecjtjd}|j}t|dy)z,Test constrained_layout for a single subplot constrainedlayoutrN)pltfigure add_subplotrfigrs rtest_constrained_layout1rB,s( **M *C  Bb!rzconstrained_layout2.pngcvtjddd\}}|jD]}t|dy)z(Test constrained_layout for 2x2 subplotsr r9r:r<rN)r=subplotsflatrrAaxsrs rtest_constrained_layout2rH4s7||Aq7HChh&R"%&rzconstrained_layout3.pngctjddd\}}t|jD]0\}}t |d}|dk(rd}nd}|j ||| 2y ) z3Test constrained_layout for colorbars with subplotsr r9r:r<rr g{Gz?{Gz?)rpadN)r=rD enumeraterEr5colorbar)rArGnnrr4rKs rtest_constrained_layout3rO<se||Aq7HCCHH%*BR"- 7CC SRS ) *rzconstrained_layout4.pngctjddd\}}|jD]}t|d}|j |ddy ) z;Test constrained_layout for a single colorbar with subplotsr r9r:r<r{Gz?rrrKshrinkNr=rDrEr5rMrArGrr4s rtest_constrained_layout4rVJsM||Aq7HChh.R"-.LL$sL3rzconstrained_layout5.pngctjddd\}}|jD]}t|d}|j |dddd y ) zZ Test constrained_layout for a single colorbar with subplots, colorbar bottom r r9r:r<rFrQrbottom)r use_gridspecrKrSlocationNrTrUs rtest_constrained_layout5r[TsX||Aq7HChh.R"-.LL#c"$rzconstrained_layout6.pngc tjd}|jdd|}|djdd}|djdd}g}|D]&}|j |}||gz }t |d(j d g}|D]&}|j |}||gz }t|d}(|j|d d d tjd y)z,Test constrained_layout for nested gridspecsr9r:rr r>r rzx-label MultiLinerQgGz?rXr"r )rrKrSrZticksN) r=r> add_gridspec subgridspecr?rrr5rMr MaxNLocator)rAgsgslgsraxslraxsrr4s rtest_constrained_layout6rhcs **M *C  !Qs  +B Q%  Aq !C Q%  Aq !C D& __R   R"%&MM&' D. __R   R"-. LL$))24rctjd}|jdd}|djdd}|djdd}g}g}t dD]2}||j ||gz }||j ||gz }4|j |djj|djjkDsJy)NTconstrained_layoutr rrr ) r=r>r`raranger?draw_without_rendering get_positiony0y1)rAGSGSAGSBaxaaxbis rtest_identical_subgridspecrw{s ** -C  !Q B Q%  Aq !C Q%  Aq !C C C 1X) A'(( A'(() q6   # #c!f&9&9&;&>&> >> >rcttjtd5tjd}t j dd}t jdd|d}t jdd|d}|D]}|j||jdddy#1swYyxYw) z2Test for proper warning if fig not set in GridSpeczhThere are no gridspecs with layoutgrids. Possibly did not call parent GridSpec with the "figure" keywordmatchr9r:rr rN) pytestwarns UserWarningr=r>rGridSpecGridSpecFromSubplotSpecr?rm)rArcrdres rtest_constrained_layout7rs 3 5 %jj .   q! $..q!RU;..q!RU; B OOB   ""$ % % %s B B..B7zconstrained_layout8.pngctjdd}tjdd|}g}dD]|}|dk(rd g}ndd g}|D]h}|j |||f}||gz }t |d |dkDr|j d |d kr|jd |jd j~|j |dddf}||gz }t |d }|j||ddy)z/Test for gridspecs that are not completely full) r"r9figsizer;r r"r]rrrr rr NrQrrR) r=r>rr~r?r5rrrrM)rArcrGjilistrvrr4s rtest_constrained_layout8rs **W] ;C   1a ,B C   6CEFE AAqD*B B4KC 2 *1u b!1u b! LL    AqD "BB4KC a (CLL$sL3rzconstrained_layout9.pngc0tjddddd\}}|jD]1}t|d}|j d|j d3j d|j|d d |jd d y)z4Test for handling suptitle and for sharex and shareyr r9Fr;sharexshareyr<rrr!rQrrRz Test SuptitleN) r=rDrEr5rr set_aspectrMsuptitlerUs rtest_constrained_layout9rs||Aq#(8HChhR"- b bMM"LL$sL3LL2L.rzconstrained_layout10.pngx86_64gMb?)r7tolctjddd\}}|jD](}|jt j dd*j dd y ) z%Test for handling legend outside axisr r9r:r^zThis is a label)labelz center left)g??)locbbox_to_anchorN)r=rDrErr*arangelegendrFs rtest_constrained_layout10rsV||Aq7HChh8  " %678II- I;rzconstrained_layout11.pngctjdd}tjdd|}tjdd|d}tjdd|d}|j |d}t |d g}|D]&}|j |}||gz }t|d }(|j|d d |j |d}t |d y )z"Test for multiple nested gridspecsr9) r r;rrr r]rrrrQ@rrSaspectN r=r>rr~rr?rr5rMrAgs0rdgsl0rrGrcr4s rtest_constrained_layout11rs **M7 ;C   Aq -C  * *1aQ 8C  + +Aq#a& 9D Q Ba C- __R  t R!,-LLSL5 Q Ba rzconstrained_layout11rat.pngctjdd}tjdd|ddg}tjdd|d}tjdd|dddg }|j |d}t |d g}|D]&}|j |}||gz }t|d }(|j|d d |j |d}t |d y)z4Test for multiple nested gridspecs with width_ratiosr9)rr rrr )r> width_ratiosr) height_ratiosrrrrrNrrs rtest_constrained_layout11ratrs **M7 ;C   AqAq6 BC  * *1aQ 8C  + +Aq#a&A OD Q Ba C- __R  t R!,-LLSL5 Q Ba rzconstrained_layout12.pngctjdd}tjdd|}|j |ddd f}|j |ddd f}t |d t |d |j |d dd f}t |d |j |ddd f}t |d |j |ddd f}t |d |j dy)z/Test that very unbalanced labeling still works.r9)rrrr r]Nr rrrT)rrr )r=r>rr~r?rr)rArax1ax2rs rtest_constrained_layout12rs **M6 :C   Aq -C //#bqb!e* %C //#ab!e* %Cr"r" QqS!V %B4 QqS!V %B4 QRU $B4 MM)rzconstrained_layout13.pngctjddd\}}|jD]%}t|d}|j ||ddd 't j t5|jjd d d d d |jjd d y #1swY+xYw)Test that padding works.r r9r:r^rr4@rJrrSrrKr)wpadhpadNUUUUUU?w_padh_pad) r=rDrEr5rMr{raises TypeErrorget_layout_enginesetrUs rtest_constrained_layout13rs||Aq7HChhCR"- SRCT BC y !4 ###34gW=44s )"B55B>zconstrained_layout14.pngctjddd\}}|jD]%}t|d}|j ||ddd '|j j d d d d y )rr r9r:r^rrrrJrgUUUUUU?皙?rrhspacewspaceN)r=rDrEr5rMrrrUs rtest_constrained_layout14rsy||Aq7HChhCR"- SRCT BCs $rzconstrained_layout15.pngcdtjd<tjdd\}}|jD]}t |dy)zTest that rcparams work.Tzfigure.constrained_layout.user r^rN)mplrcParamsr=rDrErrFs rtest_constrained_layout15r*sD59CLL01||Aq!HChh&R"%&rzconstrained_layout16.pngcvtjd\}}t|d|jgd}y)zTest ax.set_position.r9r:r^r)rr皙?rN)r=rDradd_axesrArrs rtest_constrained_layout16r3s/ll-0GCb! ,,+ ,Crzconstrained_layout17.pngcttjd}tjdd|}|j |d}|j |dddf}|j |dddd f}|j |ddd f}t |t |t |t |y) zTest uneven gridspecsr9r:r r]rrrrNr r#)r=r>rr~r?r)rArcrrax3ax4s rtest_constrained_layout17r;s **M *C   1a ,B //"T( #C //"QU) $C //"QR1W+ &C //"QRV* %Crc&tjd\}}|j}t|t|d|j t |j j|j jk(sJy)z Test twinxr9r:r<rN)r=rDtwinxrrmallrnextentsrs rtest_constrained_layout18rLslll-0GC ((*Cr" r ((C,<,<,>,F,FF GG Grcjtjd\}}|j}t|t|d|j d|j d|j t |jj|jjk(sJy)z Test twinyr9r:r<rrN) r=rDtwinyrrrmrrnrrs rtest_constrained_layout19rVsll-0GC ((*Cr"MM"LL r ((C,<,<,>,F,FF GG Grctjddd}tj||dddf}tj}|j gd}|j |||ddddf}|j|y)z)Smoke test cl does not mess up added Axesr"rN)rrrrr#)r*linspacehypotr=r>rr.rM)gximgrArmeshs rtest_constrained_layout20rbss RA B ((2r!T'{ #C **,C l #B ==RSbS#2#X /DLLrctjd\}}|jd|jt j |j j}|jd|jt j |j j}tjj||y)z>#11035: repeated calls to suptitle should not alter the layoutr9r: Suptitle0 Suptitle1N) r=rDrrmr*copyrnrtestingassert_allcloserArextents0extents1s rtest_constrained_layout21rmsll-0GCLL wwr(001HLL wwr(001HJJx2rctjd\}}|jtj|j j }|jdd|jtj|j j }tjj||y)zC#11035: suptitle should not be include in CL if manually positionedr9r:Suptitlerr1N) r=rDrmr*rrnrrrrrs rtest_constrained_layout22r|sll-0GC wwr(001HLLsL# wwr(001HJJx2rctdD]U}tjddd}|jdd}|dj dd}|j d|Wy ) zu Comment in #11035: suptitle used to cause an exception when reusing a figure w/ CL with ``clear=True``. r r9T123)r;clearnumrrrN)rlr=r>r`rar)rvrArcsubs rtest_constrained_layout23rsc 1X%jj TuE   a #e1% xs^$ %rztest_colorbar_location.pngT) remove_textr7c$dtjd<tjddd\}}|jD]/}t |}|j d|j d1|j|ddd fd |j||d dd fdd|j||dd dfddd|j||dddfdd|j||ddd|j||d dd fddy)zY Test that colorbar handling is as expected for various complicated cases... Fzpcolormesh.snaprr"r9r:rNrr)rrSr#r rrX)rrSrZrg?)rrSrZrKr toprleftright)r=rrDrEr5rrrMrUs rtest_colorbar_locationrs',CLL"#||Aq7HChhR  b bLLQT3L/LLR!VS8LDLLQUC(LMLLRVS5LALLT3L@LLQqS!VS7LCrc*tjddd\}}|djd|jt j |dj j}tjj|gdd y) Nr r9r:rFr)g/ע?g< Q?gd:tzލ?g`?h㈵>)rtol) r=rD set_visiblermr*rrnrrr)rArGrs rtest_hidden_axesrsy||Aq7HCI%  wws4y--/778HJJ:Grc dD]}tjddd\}}g}t|jD]\}}|j dt |}|j |||dd }||gz }|jj d|d k7sa|jjjg|jjjg|jg|jg|jjd d d d |j|dvrt j"j%|djj'j(|djj'j(t j"j%|d jj'j(|djj'j(t j"j%|djj'j*|d jj'j*t j"j%|djj'j*|djj'j*y)N)rrrrXr r9r:in) directionrg{Gz?)rrZrSrKrgqq?g?r)rrrr )r=rDrLrE tick_paramsr5rMrxaxis set_ticksyaxisrrrrrmr*rrrnx0ro)rZrArGcbsrNrpccbs rtest_colorbar_alignrsG6D<<1];S) 'FB NNTN *#BbR(3"&(B B4KC EE    -Qw %%b) %%b)""2&""2& ' ##&+.s $ < ""$ ( ( JJ & &s1vyy'='='?'B'B'*1vyy'='='?'B'B D JJ & &s1vyy'='='?'B'B'*1vyy'='='?'B'B D JJ & &s1vyy'='='?'B'B'*1vyy'='='?'B'B D JJ & &s1vyy'='='?'B'B'*1vyy'='='?'B'B D7Drztest_colorbars_no_overlapV.pngcbtjdd}|jdddd}|D]m}|jj t j |jdd |jddgd d gg}|j||d o|jdy)N)r rr9rr rTrrbothraxisr r rverticalr orientationfoo) r=r>rDr set_major_formatterr NullFormatterr imshowrMrrArGrims rtest_colorbars_no_overlapVr!s **VM :C ,,q!D, 6C8 $$V%9%9%;< Fd3 YYAA' ( RBJ 7 8 LLrztest_colorbars_no_overlapH.pngcbtjdd}|jd|jdddd}|D]m}|jj t j|jd d |jddgd d gg}|j||doy)N)rr r9rrrr Trrrrr r horizontalr) r=r>rrDr rrrr rrMrs rtest_colorbars_no_overlapHr$s **VM :CLL ,,q!D, 6C: $$V%9%9%;< Fd3 YYAA' ( RBL 9 :rc|tjddd\}}|djgd|j|dj }t j j|ddgddggtjddd\}}|djgd|djt jjd d }|j||d |j|dj }t j j|ddgd dggy) Nrr r9r:rrr333333?r'rrrg)\(?) r=rD set_positionrmrnr*rrr.randomrandrM)rArGpprs rtest_manually_set_positionr.s ||Aq7HCF,- Q   BJJrS#Jc #;<||Aq7HCF,- Q  299>>"b1 2BLLAL Q   BJJrS#Js #<=rztest_bboxtight.png bbox_inchestight)rr7 savefig_kwargcXtjd\}}|jdyNr9r:r%r=rDrr@s rtest_bboxtightr5s"ll-0GCMM"rz test_bbox.pngrg@r cXtjd\}}|jdyr3r4r@s r test_bboxr7 s" ll-0GCMM"rctjddddddi\}\}}}|jdd|jd |jd d |jd |jdd|jd |j |||f |j |j jj|j jj|j jjg}tjj|dj|d jg|djdd|djdk\sJy)z Tests for a bug in which constrained layout and align_ylabels on three unevenly sized subplots, one of whose y tick labels include negative numbers, drives the non-negative subplots' y labels off the edge of the plot r rr9)g@rr)rrgffffff?)r;r gridspec_kwrLabelgg?)rGr r)ratolN) r=rDset_ylimr align_ylabelsrmr rget_window_extentr*rrr)rArrr after_aligns rtest_align_labelsr@sM<<1]085DGL5MNC#sC LLANN7LLsNN7LLANN73S/* 99??44699??44699??4468KJJ A 1 1;q>3D3DE*1~00quF q>   !! !rctjd\}}|j|j|jj }|j d|jd|j|j|jj }|j|jdzkDsJ|j|jdzkDsJtjd\}}|j|j|jj }|j dd|jdd|j|j|jj }|j|jdzkDsJ|j|jdzkDsJy) Nr9r:BooBooyg$@r)r2r) r=rDrm get_tightbboxcanvas get_renderer supxlabel supylabelror)rArpos0poss rtest_suplabelsrK6sjll-0GC  CJJ335 6DMM%MM&  3::224 5C 66DGGdN "" " 66DGGdN "" "ll-0GC  CJJ335 6DMM%3MMM%3M  3::224 5C 66DGGdN "" " 66DGGdN "" "rctj}|jdd}|j|ddddf}|j y)Nr rr)r=r>r`r?rm)rArcsps rtest_gridspec_addressingrNMsE **,C  !Q B ABF $B rctjd\}}|jtjt d5tj\}}|j d|jdddtjt d5tj\}}|j ddd|jdddy#1swYixYw#1swYyxYw)NTrjzwill be deprecatedryrJr)r=rDrmr{r|PendingDeprecationWarningset_constrained_layoutr@s rtest_discouraged_apirRTslld3GC /0 2%,,.R ""4( ""$ % /0 2%,,.R ""TD#AB ""$ %% %% %%s9C&!GC rc<tjd\}}|jjgd|j |j }|j dksJ|jdksJtjd\}}|jjgd|j |j }|j dksJ|jdksJ|jdkDsJ|jdkDsJy)Nr9r:)rrrr)rectrr&r) r=rDrrrmrnx1rprro)rArpposs r test_rectrYjsll-0GC%56 ?? D 77S== 77S==ll-0GC%9: ?? D 77S== 77S== 77S== 77S==rctjddddd\}}|jD]1}|jtj j dd}3|j||j|dj}tjj|jd d |d j}tjj|jd d tjdddddd\}}|jD]1}|jtj j dd}3|j|||j|dj}tjj|jdd tjj|jdd |dj}tjj|jdd tjj|jdd y)Nr r compressedTrr(r)rgz?rQr;rgz?MbP?)r"r)r;rrrgZ| ?g+ݓ?)rr g\C?gMSt$?)r=rDrErr*r+randnrMrmrnrrrrWrpro)rArGrrrJs rtest_compressed1r_|s||Aq#'6HChh0 YYryyr2. /0LLL d) "CJJsvvvD9 d) "CJJsvvvD9||Aq#'fFHChh0 YYryyr2. /0LLL d) "CJJsvvwT:JJsvvvD9 d) "CJJsvvvD9JJsvvvD9rcXtjdddddd\}\}}|jd|jd |jd|jd |j d }|j |j d tjd d k(sJ|j d d}|j |j d dk(sJ|j d d}|j |j d dk(sJy)Nr )rrr[)g?g?r)rr)nrowsrr;r9equalrrrg -?r])absg\(\?rF) in_layout) r=rDrset_box_aspectrrmrnr{approx)rAax0rtitles rtest_compressed_suptitlerisll&4BDOC#sHHWsHHWq LL !E     "fmmF&E EE E LLDL )E     "d ** * LLEL 2E     "d ** *rz arg, state)TT)FFrVc^tj|\}}|j|usJy)Nrj)r=rDget_constrained_layout)argstaterArs rtest_set_constrained_layoutrns-llc2GC  % % '5 00 0rcbtj\}}tjt5|j d|j sJ|j d|j rJ|j d|j sJ dddy#1swYyxYw)NTF)r=rDr{r|rPrQrkr@s rtest_constrained_togglerpsllnGC / 0, ""4())+++ ""5)--/// ""4())+++ ,,,s A*B%%B.ctjdd}|j|jtjd~t j tdt jDrJy)NT)rr)rkrrc3dK|](}t|tjj*yw)N) isinstancer _layoutgrid LayoutGrid).0objs r z#test_layout_leak..s)0c3??#=#=>0s.0) r=r>r?rmclosegccollectany get_objects)rAs rtest_layout_leakr~sm **h ?COO IIe JJL0 nn.000 00rcHtjdd}|jdd}g}|jD]w}|j dd}t dD]/}||j ||dfgz }|dj1|j |d d dfjy|j|dd D]U}tj|jjd|djjdd rUJy ) z Test that the submerged margin logic does not get called multiple times on same axes if it is already in a subfigure )rr"r9rr rr rr#Ngư>r\) r=r> subfiguresflattenr`rlr?rrmr*allclosernbounds)rAfiguresrGfrcrvrs rtest_submerged_subfigrs **VM :CnnQ"G C __ ' ^^Aq !q A AMM"QT(+, ,C GLLN  bAh$$& '  !"gH{{2??,33B7q6..077;$H HHHr)r^F)r^)Frzplatformnumpyr*r{ matplotlibrmatplotlib.testing.decoratorsrmatplotlib.pyplotpyplotr=matplotlib.transforms transforms mtransformsrrmark usefixtures pytestmarkrr5rBrHrOrVr[rhrwrrrmachinerrrrrrrrrrrrrrrrrrr!r$r.r5Bboxr7r@rKrNrRrTrYr_ri parametrizernrpr~rrrrs  :+' KK/0  ,-W=">",-W=&>&,-W= *> *,-W=4>4,-W= $> $,-W=4>4.?( % ,-W=4>46,-W= /> /-.g+8++-9auF<F<-.g>!?!&01A!B!&-.g>?*-.g>>?>-.g>$?$-.g>&?&-.g>-?--.g> ?  H H 3 3 %/0"'3D3D* GD@34GDE34GD:E: > '("'!. 8:: ?#"'!.!1!1!1C8c1X2F!G!IJ J "D#.!%"! $:>+0J d^T ( 1  1 , 0Hr