rL iZtdZddlZddlZddlmZddlZddlZddlm Z m Z m Z ddl m Z ejeZGddZGdd eZGd d eZGd d ZGddZy)a :mod:`~matplotlib.gridspec` contains classes that help to layout multiple `~.axes.Axes` in a grid-like pattern within a figure. The `GridSpec` specifies the overall grid structure. Individual cells within the grid are referenced by `SubplotSpec`\s. Often, users need not access this module directly, and can use higher-level methods like `~.pyplot.subplots`, `~.pyplot.subplot_mosaic` and `~.Figure.subfigures`. See the tutorial :ref:`arranging_axes` for a guide. N)Integral)_api_pylab_helpers _tight_layout)BboxceZdZdZddZdZeddZedd Zd Z dd Z dd Z d Z dZ dZdZdZedZdZddddddZy) GridSpecBasezm A base class of GridSpec that specifies the geometry of the grid that a subplot will be placed. Nct|tr|dkrtd|t|tr|dkrtd|||c|_|_|j ||j |y)a Parameters ---------- nrows, ncols : int The number of rows and columns of the grid. width_ratios : array-like of length *ncols*, optional Defines the relative widths of the columns. Each column gets a relative width of ``width_ratios[i] / sum(width_ratios)``. If not given, all columns will have the same width. height_ratios : array-like of length *nrows*, optional Defines the relative heights of the rows. Each row gets a relative height of ``height_ratios[i] / sum(height_ratios)``. If not given, all rows will have the same height. rz/Number of rows must be a positive integer, not z2Number of columns must be a positive integer, not N) isinstancer ValueError_nrows_ncolsset_height_ratiosset_width_ratios)selfnrowsncols height_ratios width_ratioss Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/gridspec.py__init__zGridSpecBase.__init__ s%*eqjA%KM M%*eqjDUINP P#(%  T[ }- l+cJtt|jdk7rd|jnd}tt|jdk7rd|jnd}dj |j j |j|j||zS)Nz, height_ratios=z, width_ratios=z&{clsname}({nrows}, {ncols}{optionals}))clsnamerr optionals) lenset_row_height_ratios_col_width_ratiosformat __class____name__r r)r height_arg width_args r__repr__zGridSpecBase.__repr__9sS!8!89:a?))@)@(CDEG C 6 678A='t'='=&@ACE 7>>NN++++++ 9, ? rc|jSN)r rs rzGridSpecBase.E $++rzThe number of rows in the grid.)docc|jSr))rr*s rr+zGridSpecBase.Gr,rz"The number of columns in the grid.c2|j|jfS)zW Return a tuple containing the number of rows and columns in the grid. )r rr*s r get_geometryzGridSpecBase.get_geometryJs{{DKK''rcyr))rfigures rget_subplot_paramszGridSpecBase.get_subplot_paramsPs rc2|\}}||||z|||zf}|S)a[ Create and return a `.SubplotSpec` instance. Parameters ---------- loc : (int, int) The position of the subplot in the grid as ``(row_index, column_index)``. rowspan, colspan : int, default: 1 The number of rows and columns the subplot should span in the grid. r2)rlocrowspancolspanloc1loc2 subplotspecs rnew_subplotspeczGridSpecBase.new_subplotspecTs4 d4W ,d4<.??@ rc|dg|jz}||_yt||jk7r td||_y)z Set the relative widths of the columns. *width_ratios* must be of length *ncols*. Each column gets a relative width of ``width_ratios[i] / sum(width_ratios)``. NrzTExpected the given number of width ratios to match the number of columns of the grid)rrr r!)rrs rrzGridSpecBase.set_width_ratiosdsT  3,L". $++ -GH H!-rc|jS)zo Return the width ratios. This is *None* if no width ratios have been set explicitly. )r!r*s rget_width_ratioszGridSpecBase.get_width_ratiosrs %%%rc|dg|jz}||_yt||jk7r td||_y)z Set the relative heights of the rows. *height_ratios* must be of length *nrows*. Each row gets a relative height of ``height_ratios[i] / sum(height_ratios)``. NrzRExpected the given number of height ratios to match the number of rows of the grid)r rr r )rrs rrzGridSpecBase.set_height_ratioszsT  C$++-M#0 4;; .DE E"/rc|jS)zq Return the height ratios. This is *None* if no height ratios have been set explicitly. )r r*s rget_height_ratioszGridSpecBase.get_height_ratioss &&&rc|j\}}|j|}|j}|j}|j}|j }|j } |j} ||z } ||z } | || |dz zzz } | | z}| |zt|jz }|jDcgc]}||z }}dg|g|dz zz}tjtj||gj}| || |dz zzz }| |z}||zt|jz }|jDcgc]}||z }}dg|g|dz zz}tjtj||gj}||z jdj \}}||zjdj \}}||||fScc}wcc}w)a Return the positions of the grid cells in figure coordinates. Parameters ---------- fig : `~matplotlib.figure.Figure` The figure the grid should be applied to. The subplot parameters (margins and spacing between subplots) are taken from *fig*. Returns ------- bottoms, tops, lefts, rights : array The bottom, top, left, right positions of the grid cells in figure coordinates. rr))r0r4leftrightbottomtopwspacehspacesumr npcumsum column_stackflatr!reshapeT)rfigrrsubplot_paramsrFrGrHrIrJrK tot_width tot_heightcell_hsep_hnormr cell_heights sep_heightscell_hscell_wsep_w cell_widths sep_widthscell_wsfig_tops fig_bottoms fig_lefts fig_rightss rget_grid_positionszGridSpecBase.get_grid_positionss ((* u005""$$&&  &&&&DL 6\ uvuQw'778~D$;$; <<*.*A*ABQDB BceWa01 ))BOO[,,GHMMNefeAg&667~D$:$: ;;)-)?)?@Aq4x@ @SUGuQw/0 ))BOOZ,EFKKL!$w 7 7 @ B B+!% 8 8 A C C :Hi;;CAs 3 G> Gc|jD]X}|j}|t|dr|jj}|j ||fk(sV|cSt |||S)zo Check if the figure already has a gridspec with these dimensions, or create a new one get_topmost_subplotspecr3)get_axes get_gridspechasattrrir0GridSpec)r3rraxgss r_check_gridspec_existsz#GridSpecBase._check_gridspec_existssx //# B"B~289 335BBDB??$6I uV44rc*|j\}}d}t|tr4 |\}}t j |||d|||dg||f\}} n||||zd\}} t ||| S#t$r}td|d}~wwxYw)z,Create and return a `.SubplotSpec` instance.c|}t|tr,|j|\}}}||kDr||dz fStd|dkr||z}d|cxkr|kr||fS|td|d|d|td|d|)Nrz=GridSpec slice would result in no space allocated for subplotrzindex z is out of bounds for axis z with size z) is out of bounds for GridSpec with size )r sliceindices IndexError)keysizeaxisorig_keystartstop_s r _normalizez,GridSpecBase.__getitem__.._normalizesH#u%!$T!2tQ%< $(?* "9::7*C?d?8O#%$vhZ8--1F+dV&EFF%vhZ8;;?&&BCCrzUnrecognized subplot specNrr)r0r tupler rMravel_multi_index SubplotSpec) rrwrrr~k1k2errnum1num2s r __getitem__zGridSpecBase.__getitem__s((* u C( c5 ! GB--Bq):b%+CD JD$$C=JD$4t,, G !<=3F GsA88 B B  BFT)sharexshareysqueeze subplot_kwc6|j}| tdt|ts|rdnd}t|ts|rdnd}t j gd|||i}|j }tj|j|jft}t|jD]]}t|jD]C}d|d||d f|d |fd } | ||d <| ||d <|j|||ffi||||f<E_|d vr#|jD]} | jd|dvr#|jD]} | j!d|r/|j"dk(r|j%S|j'S|S)z Add all subplots specified by this `GridSpec` to its parent figure. See `.Figure.subplots` for detailed documentation. NzIGridSpec.subplots() only works for GridSpecs created with a parent figureallnone)rrowcolrFT)rr)dtype)rrr)rrrrrr)rrT)skip_non_rectangular_axes)rrr)r3r r strr check_in_listcopyrMemptyr robjectrange add_subplotrP_label_outer_xaxis_label_outer_yaxisrxitemr) rrrrrr3axarrrr shared_withros rsubplotszGridSpecBase.subplotss ><= =&#&$U&F&#&$U&F E"( 9  J__& $++t{{36B% 2CT[[) 2'+E$K&+CFmE!S&MK '26': 8$'26': 8$"4&"4"4cN#2&0#2c3h  2 2 ^ #jj F%%%E F ^ #jj F%%%E F $)::?5::< G  GLr)NNr))rr)r$ __module__ __qualname____doc__rr'propertyrrr0r4r<rr?rrBrg staticmethodrqrrr2rrr r s ,2  -: ,,.S\\"3A"566.B.'-"-K))F$6$67K N4;L;LMaaq!11MN. Ns B8B cZ|jDcgc]}t||s|c}Scc}w)z Return a list of the names of the subplot parameters explicitly set in the GridSpec. This is a subset of the attributes of `.SubplotParams`. )rr)rrs rlocally_modified_subplot_paramsz(GridSpec.locally_modified_subplot_paramss' ,,Aaa0@AAAs((c ||j}tj||jtj|j||||||}|r|j di|yy)a Adjust subplot parameters to give specified padding. Parameters ---------- figure : `.Figure` The figure. renderer : `.RendererBase` subclass, optional The renderer to be used. pad : float Padding between the figure edge and the edges of subplots, as a fraction of the font-size. h_pad, w_pad : float, optional Padding (height/width) between edges of adjacent subplots. Defaults to *pad*. rect : tuple (left, bottom, right, top), default: None (left, bottom, right, top) rectangle in normalized figure coordinates that the whole subplots area (including labels) will fit into. Default (None) is the whole figure. N) grid_spec)padh_padw_padrectr2) _get_rendererrget_tight_layout_figurerget_subplotspec_listr)rr3rendererrrrrrs r tight_layoutzGridSpec.tight_layoutsl,  ++-H66 FKK  . .v{{d K #U%dD  DKK !& ! r) NNNNNNNNNr))NgHzG?NNN) r$rrrrrrr4rr __classcell__r#s@rrnrn/sB-19=%)2646lJLQ8.B-1<@"rrnc6eZdZdZ dfd ZddZdZxZS)GridSpecFromSubplotSpeczx GridSpec whose subplot layout parameters are inherited from the location specified by a given SubplotSpec. c||_||_t|tr||_n t d|jj j|_t|%||||y)ak Parameters ---------- nrows, ncols : int Number of rows and number of columns of the grid. subplot_spec : SubplotSpec Spec from which the layout parameters are inherited. wspace, hspace : float, optional See `GridSpec` for more details. If not specified default values (from the figure or rcParams) are used. height_ratios : array-like of length *nrows*, optional See `GridSpecBase` for details. width_ratios : array-like of length *ncols*, optional See `GridSpecBase` for details. zVsubplot_spec must be type SubplotSpec, usually from GridSpec, or axes.get_subplotspec.rN) _wspace_hspacer r _subplot_spec TypeErrorrlr3rr) rrr subplot_specrJrKrrr#s rrz GridSpecFromSubplotSpec.__init__st&  lK 0!-D NO O((557>>  &2'4  6rc|j |jn*||jjntjd}|j |j n*||jj ntjd}|jj|}|j\}}}}t||||||S)z1Return a dictionary of subplot layout parameters.zfigure.subplot.hspacezfigure.subplot.wspace)rFrGrHrIrJrK) rrrKrrrrJrrextentsr) rr3rKrJfigboxrFrHrGrIs rr4z*GridSpecFromSubplotSpec.get_subplot_paramss"&,,":$,,4:4Fv))00||$;< #',,":$,,4:4Fv))00||$;< ##008#)>> feS$e$*$*6; ;rc6|jjS)zY Return the topmost `.SubplotSpec` instance associated with the subplot. )rrir*s rriz/GridSpecFromSubplotSpec.get_topmost_subplotspecs!!99;;r)NNNNr))r$rrrrr4rirrs@rrrs  &*266@; rct|dk(rS|\}t|tr|St|tst d| t t t|\}}}n6t|dk(r|\}}}n!tjddt|tj|||}|t|||}t|tr4t|d k(r&td |Dst d ||\}}n5t|tr |dks|||zkDrt d ||zd ||x}}||dz |S#t$rt d|dwxYw)z Construct a `.SubplotSpec` from a parent `.Figure` and either - a `.SubplotSpec` -- returned as is; - one or three numbers -- a MATLAB-style subplot specifier. rz>Single argument to subplot must be a three-digit integer, not Nsubplotz1 or 3)takesgivenrjrEc3<K|]}t|tywr))r r).0ns r z1SubplotSpec._from_subplot_args..Fs<1z!X.DC#{+ X. $$'7,-- 7"%c3s8"4dC Y!^"OD$""9HCIN N  , ,VT4 @ :$V4B c5 !c#h!m<<< I#ODAqc8,a3d? >tDykJ'#KA!A#ay3 7 $$'7,-267 7s EEcJ|j |jS|jSr))_num2rr*s rrzSubplotSpec.num2Ws JJ.tyy>DJJ>rc||_yr))r)rvalues rrzSubplotSpec.num2[s  rc|jSr))rr*s rrlzSubplotSpec.get_gridspec_s ~~rcx|jj\}}|||j|jfS)a Return the subplot geometry as tuple ``(n_rows, n_cols, start, stop)``. The indices *start* and *stop* define the range of the subplot within the `GridSpec`. *stop* is inclusive (i.e. for a single cell ``start == stop``). )rlr0rr)rrrs rr0zSubplotSpec.get_geometrybs6&&(557 dT499dii//rc|jj}t|j|z|j|zdzS)z6The rows spanned by this subplot, as a `range` object.r)rlrrrr)rrs rr7zSubplotSpec.rowspanms<!!#))TYY%'e);a)?@@rc|jj}t|j|z|j|zg\}}t ||dzS)z9The columns spanned by this subplot, as a `range` object.r)rlrsortedrrr)rrc1c2s rr8zSubplotSpec.colspanssP!!#))U*DII,=>?BRa  rc4|jjdk(SNr)r7r{r*s r is_first_rowzSubplotSpec.is_first_row|||!!Q&&rcd|jj|jjk(Sr))r7r|rlrr*s r is_last_rowzSubplotSpec.is_last_row&||  D$5$5$7$=$===rc4|jjdk(Sr )r8r{r*s r is_first_colzSubplotSpec.is_first_colr rcd|jj|jjk(Sr))r8r|rlrr*s r is_last_colzSubplotSpec.is_last_colrrc|j}|j\}}tj|j|j g||f\}}|j |\}}} } ||j} ||j} | |j} | |j}tj| | || S)zJ Update the subplot position from ``figure.subplotpars``. ) rlr0rM unravel_indexrrrgminmaxr from_extents)rr3rrrrrrdrcrerf fig_bottomfig_topfig_left fig_rights rrzSubplotSpec.get_positions$$&,,. u%%tyy$))& **^?? [[ 0AA !!'>'>K  7<(Errc(eZdZdZ ddZ ddZy)rzM Parameters defining the positioning of a subplots grid in a figure. NcdD]#}t||tjd|%|j||||||y)au Defaults are given by :rc:`figure.subplot.[name]`. Parameters ---------- left : float The position of the left edge of the subplots, as a fraction of the figure width. right : float The position of the right edge of the subplots, as a fraction of the figure width. bottom : float The position of the bottom edge of the subplots, as a fraction of the figure height. top : float The position of the top edge of the subplots, as a fraction of the figure height. wspace : float The width of the padding between subplots, as a fraction of the average Axes width. hspace : float The height of the padding between subplots, as a fraction of the average Axes height. rrN)rrrr)rrFrHrGrIrJrKrws rrzSubplotParams.__init__sH4J FC D#s||ocU,CD E F D&%ff=rc"||n |j||n |jk\r td||n |j||n |jk\r td|||_|||_|||_|||_|||_|||_yy)zY Update the dimensions of the passed parameters. *None* means unchanged. Nzleft cannot be >= rightzbottom cannot be >= top)rFrGr rHrIrJrK)rrFrHrGrIrJrKs rrzSubplotParams.updates %T499".EDJJ @67 7)Vt{{?C :67 7  DI  DJ   DK ?DH   DK   DK r)NNNNNN)r$rrrrrr2rrrrs$@D%)><>B#'!rr)rrloggingnumbersrnumpyrM matplotlibrrrrmatplotlib.transformsr getLoggerr$_logr rnrrrr2rrr1sx  ::&w"RRj["|["|9