
    P/PhZt                         d Z ddlZddlZddlmZ ddlZddlZddlm	Z	m
Z
mZ ddlmZ  ej        e          Z G d d          Z G d d	e          Z G d
 de          Z G d d          Z G d d          ZdS )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)Bboxc                       e Zd ZdZddZd Z ed d          Z ed d	          Zd
 Z	ddZ
ddZd Zd Zd Zd Zd Zed             Zd ZddddddZdS )GridSpecBasezm
    A base class of GridSpec that specifies the geometry of the grid
    that a subplot will be placed.
    Nc                 ,   t          |t                    r|dk    rt          d|          t          |t                    r|dk    rt          d|          ||c| _        | _        |                     |           |                     |           dS )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.
        r   z/Number of rows must be a positive integer, not z2Number of columns must be a positive integer, not N)
isinstancer   
ValueError_nrows_ncolsset_height_ratiosset_width_ratios)selfnrowsncolsheight_ratioswidth_ratioss        S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/matplotlib/gridspec.py__init__zGridSpecBase.__init__    s     %** 	MeqjjK%KKM M M%** 	PeqjjNUNNP P P#(% T[}---l+++++    c                 &   t          t          | j                            dk    r
d| j        nd}t          t          | j                            dk    r
d| j        nd}d                    | j        j        | j        | j        ||z             S )N   z, height_ratios= z, width_ratios=z&{clsname}({nrows}, {ncols}{optionals}))clsnamer   r   	optionals)	lenset_row_height_ratios_col_width_ratiosformat	__class____name__r   r   )r   
height_arg	width_args      r   __repr__zGridSpecBase.__repr__9   s    S!899::a?? E)@DDDEG 	 C 67788A== Bt'=AAACE 	7>>N+++ 9,	 ?   	r   c                     | j         S N)r   r   s    r   <lambda>zGridSpecBase.<lambda>E       $+ r   zThe number of rows in the grid.)docc                     | j         S r)   )r   r*   s    r   r+   zGridSpecBase.<lambda>G   r,   r   z"The number of columns in the grid.c                     | j         | j        fS )zW
        Return a tuple containing the number of rows and columns in the grid.
        )r   r   r*   s    r   get_geometryzGridSpecBase.get_geometryJ   s     {DK''r   c                     d S r)    )r   figures     r   get_subplot_paramszGridSpecBase.get_subplot_paramsP   s    r   r   c                 8    |\  }}| |||z   |||z   f         }|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   )r   locrowspancolspanloc1loc2subplotspecs          r   new_subplotspeczGridSpecBase.new_subplotspecT   s4     
d4W,d4<.??@r   c                 ~    |dg| j         z  }n't          |          | j         k    rt          d          || _        dS )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)``.
        Nr   zTExpected the given number of width ratios to match the number of columns of the grid)r   r   r   r!   )r   r   s     r   r   zGridSpecBase.set_width_ratiosd   sX     3,LL$+-- G H H H!-r   c                     | j         S )zo
        Return the width ratios.

        This is *None* if no width ratios have been set explicitly.
        )r!   r*   s    r   get_width_ratioszGridSpecBase.get_width_ratiosr   s     %%r   c                 ~    |dg| j         z  }n't          |          | j         k    rt          d          || _        dS )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)``.
        Nr   zRExpected the given number of height ratios to match the number of rows of the grid)r   r   r   r    )r   r   s     r   r   zGridSpecBase.set_height_ratiosz   sX      C$+-MM4;.. D E E E"/r   c                     | j         S )zq
        Return the height ratios.

        This is *None* if no height ratios have been set explicitly.
        )r    r*   s    r   get_height_ratioszGridSpecBase.get_height_ratios   s     &&r   c                 8   |                                  \  }}|                     |          }|j        }|j        }|j        }|j        }|j        }	|j        }
||z
  }||z
  }|||
|dz
  z  z   z  }|
|z  }||z  t          | j	                  z  fd| j	        D             }dg|g|dz
  z  z   }t          j        t          j        ||g          j                  }|||	|dz
  z  z   z  }|	|z  }||z  t          | j                  z  fd| j        D             }dg|g|dz
  z  z   }t          j        t          j        ||g          j                  }||z
                      d          j        \  }}||z                       d          j        \  }}||||fS )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.
        r   c                     g | ]}|z  S r2   r2   .0rnorms     r   
<listcomp>z3GridSpecBase.get_grid_positions.<locals>.<listcomp>   s    BBBQDBBBr   r   c                     g | ]}|z  S r2   r2   rE   s     r   rI   z3GridSpecBase.get_grid_positions.<locals>.<listcomp>   s    @@@Aq4x@@@r   )   )r0   r4   leftrightbottomtopwspacehspacesumr    npcumsumcolumn_stackflatr!   reshapeT)r   figr   r   subplot_paramsrM   rN   rO   rP   rQ   rR   	tot_width
tot_heightcell_hsep_hcell_heightssep_heightscell_hscell_wsep_wcell_widths
sep_widthscell_wsfig_topsfig_bottoms	fig_lefts
fig_rightsrH   s                              @r   get_grid_positionszGridSpecBase.get_grid_positions   s     ((**u0055"$& &&DL	6\
 uvuQw'778~D$; < <<BBBB$*ABBBceWa01)BO[,,GHHMNN efeAg&667~D$: ; ;;@@@@)?@@@SUGuQw/0
)BOZ,EFFKLL!$w 7 7 @ @ B+!% 8 8 A A C	:Hi;;r   c                 (   |                                  D ]l}|                                }|Tt          |d          r&|                                                                }|                                ||fk    r|c S mt          |||           S )zo
        Check if the figure already has a gridspec with these dimensions,
        or create a new one
        Nget_topmost_subplotspecr3   )get_axesget_gridspechasattrrn   r0   GridSpec)r3   r   r   axgss        r   _check_gridspec_existsz#GridSpecBase._check_gridspec_exists   s     //## 	 	B""B~2899 E 3355BBDDB??$$66IIIuV4444r   c                 `   |                                  \  }}d }t          |t                    r\	 |\  }}n"# t          $ r}t          d          |d}~ww xY wt	          j         |||d           |||d          g||f          \  }}	n ||||z  d          \  }}	t          | ||	          S )z,Create and return a `.SubplotSpec` instance.c                 6   | }t          | t                    r5|                     |          \  }}}||k    r||dz
  fS t          d          | dk     r| |z   } d| cxk    r|k     rn n| | fS |t          d| d| d|           t          d| d|           )Nr   z=GridSpec slice would result in no space allocated for subplotr   zindex z is out of bounds for axis z with size z) is out of bounds for GridSpec with size )r   sliceindices
IndexError)keysizeaxisorig_keystartstop_s          r   
_normalizez,GridSpecBase.__getitem__.<locals>._normalize   s   H#u%% C!$T!2!2tQ%<< $(?*  "9 : : : 77*C????d?????8O%$ &Eh &E &E-1&E &E>B&E &E F F F % &Bh &B &B;?&B &B C C Cr   zUnrecognized subplot specNr   r   )r0   r   tupler   rT   ravel_multi_indexSubplotSpec)
r   r|   r   r   r   k1k2errnum1num2s
             r   __getitem__zGridSpecBase.__getitem__   s    ((**u	C 	C 	C( c5!! 		>GBB G G G !<==3FG-Bq))::b%+C+CD   JD$$ $C==JD$4t,,,s   7 
AAAFT)sharexshareysqueeze
subplot_kwc                D   | j         }|t          d          t          |t                    s|rdnd}t          |t                    s|rdnd}t	          j        g d||           |i }|                                }t          j        | j	        | j
        ft                    }t          | j	                  D ]g}t          | j
                  D ]P}d|d         ||d	f         |d	|f         d
}	|	|         |d<   |	|         |d<    |j        | ||f         fi ||||f<   Qh|dv r |j        D ]}
|
                    d           |dv r |j        D ]}
|
                    d           |r3|j        dk    r|                                n|                                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 figureallnone)r   rowcolr   FT)r   r   )dtype)r   r   r   )r   r   r   r   r   r   )r   r   T)skip_non_rectangular_axes)r   r   r   )r3   r   r   strr   check_in_listcopyrT   emptyr   r   objectrangeadd_subplotrW   _label_outer_xaxis_label_outer_yaxisr}   itemr   )r   r   r   r   r   r3   axarrr   r   shared_withrt   s              r   subplotszGridSpecBase.subplots   s(    > < = = = &#&& 	1$0UU&F&#&& 	1$0UU&FEEE"(	9 	9 	9 	9J__&&
 $+t{36BBB%% 	2 	2CT[)) 2 2'+E$K&+CFmE!S&MK K'26':
8$'26':
8$"4&"4cN#2 #2&0#2 #2c3h2 ^##j F F%%%EEEE^##j F F%%%EEEE 	 $):??5::<<<G Lr   )NNr)   )r   r   )r$   
__module____qualname____doc__r   r'   propertyr   r   r0   r4   r<   r   r?   r   rB   rl   staticmethodrv   r   r   r2   r   r   r	   r	      sT        
, , , ,2
 
 
 H--:< < <EH--=? ? ?E( ( (       . . .& & &0 0 0' ' '-< -< -<^ 5 5 \5(#- #- #-J "'ud 3 3 3 3 3 3 3r   r	   c                   T     e Zd ZdZ	 	 	 	 d
 fd	Zg dZd ZddZd Z	 	 dd	Z	 xZ
S )rs   a  
    A grid layout to place subplots within a figure.

    The location of the grid cells is determined in a similar way to
    `.SubplotParams` using *left*, *right*, *top*, *bottom*, *wspace*
    and *hspace*.

    Indexing a GridSpec instance returns a `.SubplotSpec`.
    Nc                     || _         || _        || _        || _        || _        |	| _        || _        t                                          |||
|           dS )a  
        Parameters
        ----------
        nrows, ncols : int
            The number of rows and columns of the grid.

        figure : `.Figure`, optional
            Only used for constrained layout to create a proper layoutgrid.

        left, right, top, bottom : float, optional
            Extent of the subplots as a fraction of figure width or height.
            Left cannot be larger than right, and bottom cannot be larger than
            top. If not given, the values will be inferred from a figure or
            rcParams at draw time. See also `GridSpec.get_subplot_params`.

        wspace : float, optional
            The amount of width reserved for space between subplots,
            expressed as a fraction of the average axis width.
            If not given, the values will be inferred from a figure or
            rcParams when necessary. See also `GridSpec.get_subplot_params`.

        hspace : float, optional
            The amount of height reserved for space between subplots,
            expressed as a fraction of the average axis height.
            If not given, the values will be inferred from a figure or
            rcParams when necessary. See also `GridSpec.get_subplot_params`.

        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.

        r   r   N)	rM   rO   rN   rP   rQ   rR   r3   superr   )r   r   r   r3   rM   rO   rN   rP   rQ   rR   r   r   r#   s               r   r   zGridSpec.__init__9  sl    T 	
&2'4 	 	6 	6 	6 	6 	6r   rM   rO   rN   rP   rQ   rR   c                 J   |                                 D ]1\  }}|| j        v rt          | ||            t          | d          t          j        j                                        D ]}|j        j	        j
        D ]}|                                |                                                                }|                                | k    rP|                    d          }|                    |                                                    |                     dS )a  
        Update the subplot parameters of the grid.

        Parameters that are not explicitly given are not changed. Setting a
        parameter to *None* resets it to :rc:`figure.subplot.*`.

        Parameters
        ----------
        left, right, top, bottom : float or None, optional
            Extent of the subplots as a fraction of figure width or height.
        wspace, hspace : float, optional
            Spacing between the subplots as a fraction of the average subplot
            width / height.
        z is an unknown keywordNF)root)items_AllowedKeyssetattrAttributeErrorr   Gcffigsvaluescanvasr3   axesget_subplotspecrn   rq   
get_figure_set_positionget_position)r   kwargskv
figmanagerrt   ssrZ   s           r   updatezGridSpec.updateq  s0    LLNN 	C 	CDAqD%%%a####$%A%A%ABBB(,188:: 	Q 	QJ '.3 Q Q%%''3++--EEGGB((D00 mmm77((););)=)=)J)J3)O)OPPPQ	Q 	Qr   c                      |d  j         D             }t          di |}nt          j        |j                  } |j        di  fd j         D              |S )a:  
        Return the `.SubplotParams` for the GridSpec.

        In order of precedence the values are taken from

        - non-*None* attributes of the GridSpec
        - the provided *figure*
        - :rc:`figure.subplot.*`

        Note that the ``figure`` attribute of the GridSpec is always ignored.
        Nc                 :    i | ]}|t           j        d |z            S )figure.subplot.)mplrcParams)rF   r   s     r   
<dictcomp>z/GridSpec.get_subplot_params.<locals>.<dictcomp>  s7     . . . S\"3A"56 . . .r   c                 2    i | ]}|t          |          S r2   getattrrF   r   r   s     r   r   z/GridSpec.get_subplot_params.<locals>.<dictcomp>  s%    MMMaaq!1!1MMMr   r2   )r   SubplotParamsr   subplotparsr   )r   r3   kwr   s   `   r   r4   zGridSpec.get_subplot_params  s     >. .,. . .B'--"--KK)F$677KNNMMMM4;LMMMNNNr   c                 *      fd j         D             S )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`.
        c                 4    g | ]}t          |          |S r2   r   r   s     r   rI   z<GridSpec.locally_modified_subplot_params.<locals>.<listcomp>  s(    AAAaa0@0@AAAAr   )r   r*   s   `r   locally_modified_subplot_paramsz(GridSpec.locally_modified_subplot_params  s#     BAAA4,AAAAr   HzG?c           
          ||                                 }t          j        ||j        t          j        |j        |           |||||          }|r | j        di | dS dS )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)padh_padw_padrectr2   )_get_rendererr   get_tight_layout_figurer   get_subplotspec_listr   )r   r3   rendererr   r   r   r   r   s           r   tight_layoutzGridSpec.tight_layout  s    , ++--H6FK.v{dKKK#U%dD D D  	"DK!!&!!!!!	" 	"r   )	NNNNNNNNNr)   )Nr   NNN)r$   r   r   r   r   r   r   r4   r   r   __classcell__r#   s   @r   rs   rs   /  s          -19=%)2646 46 46 46 46 46l JIILQ Q Q8   .B B B -1<@" " " " " " " "r   rs   c                   6     e Zd ZdZ	 	 d fd	ZddZd Z xZS )GridSpecFromSubplotSpeczx
    GridSpec whose subplot layout parameters are inherited from the
    location specified by a given SubplotSpec.
    Nc                    || _         || _        t          |t                    r|| _        nt          d          | j                                        j        | _        t                      	                    ||||           dS )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.r   N)
_wspace_hspacer   r   _subplot_spec	TypeErrorrq   r3   r   r   )	r   r   r   subplot_specrQ   rR   r   r   r#   s	           r   r   z GridSpecFromSubplotSpec.__init__  s    & lK00 	O!-DNO O O (5577>&2'4 	 	6 	6 	6 	6 	6r   c                 0   | j         | j         n||j        j        nt          j        d         }| j        | j        n||j        j        nt          j        d         }| j                            |          }|j	        \  }}}}t          ||||||          S )z1Return a dictionary of subplot layout parameters.Nzfigure.subplot.hspacezfigure.subplot.wspace)rM   rN   rO   rP   rQ   rR   )r   r   rR   r   r   r   rQ   r   r   extentsr   )	r   r3   rR   rQ   figboxrM   rO   rN   rP   s	            r   r4   z*GridSpecFromSubplotSpec.get_subplot_params  s    "&,":$,,4:4Fv)00|$;< 	 #',":$,,4:4Fv)00|$;< 	 #0088#)> feS$e$*$*6; ; ; 	;r   c                 4    | j                                         S )zY
        Return the topmost `.SubplotSpec` instance associated with the subplot.
        )r   rn   r*   s    r   rn   z/GridSpecFromSubplotSpec.get_topmost_subplotspec  s     !99;;;r   )NNNNr)   )r$   r   r   r   r   r4   rn   r   r   s   @r   r   r     ss          &*266 6 6 6 6 6@; ; ; ; < < < < < < <r   r   c                       e Zd ZdZddZd Zed             Zed             Z	e	j
        d             Z	d Zd	 Zed
             Zed             Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )r   a]  
    The location of a subplot in a `GridSpec`.

    .. note::

        Likely, you will never instantiate a `SubplotSpec` yourself. Instead,
        you will typically obtain one from a `GridSpec` using item-access.

    Parameters
    ----------
    gridspec : `~matplotlib.gridspec.GridSpec`
        The GridSpec, which the subplot is referencing.
    num1, num2 : int
        The subplot will occupy the *num1*-th cell of the given
        *gridspec*.  If *num2* is provided, the subplot will span between
        *num1*-th cell and *num2*-th cell **inclusive**.

        The index starts from 0.
    Nc                 0    || _         || _        || _        d S r)   )	_gridspecr   r   )r   gridspecr   r   s       r   r   zSubplotSpec.__init__  s    !				r   c           
          |                                   d| j        j         d| j        j         d| j        j         d| j        j         d
S )N[:z, ])rq   r7   r   r   r8   r*   s    r   r'   zSubplotSpec.__repr__"  sm    $$&& = =<%= =(,(9= =<%= =(,(9= = = 	>r   c                 f   t          |          dk    r|\  }t          |t                    r|S t          |t                    st	          d|          	 t          t          t          |                    \  }}}n_# t          $ r t	          d|          dw xY wt          |          dk    r|\  }}}n$t          j	        ddt          |                    t                              | ||          }|t          |||           }t          |t                    rDt          |          d	k    r1t          d
 |D                       st	          d|           |\  }}n@t          |t                    r|dk     s	|||z  k    rt	          d||z   d|          |x}}||dz
  |         S )z
        Construct a `.SubplotSpec` from a parent `.Figure` and either

        - a `.SubplotSpec` -- returned as is;
        - one or three numbers -- a MATLAB-style subplot specifier.
        r   z>Single argument to subplot must be a three-digit integer, not N   subplotz1 or 3)takesgivenro   rL   c              3   @   K   | ]}t          |t                    V  d S r)   )r   r   )rF   ns     r   	<genexpr>z1SubplotSpec._from_subplot_args.<locals>.<genexpr>F  s,      <<1z!X..<<<<<<r   z3Subplot specifier tuple must contain integers, not z(num must be an integer with 1 <= num <= z, not )r   r   r   r   r   mapintr   r   nargs_errorrs   rv   r   r   )	r3   argsargrowscolsnumru   ijs	            r   _from_subplot_argszSubplotSpec._from_subplot_args'  s    t99>>DC#{++ -
X.. - ,$', ,- - -7"%c3s88"4"4dCC 7 7 7 ,$', ,- -2677 YY!^^"OD$"9HCIINNNN,,VT4@@:$V444Bc5!! 	c#hh!mm<<<<<<<  O#OO   DAqqc8,, a3d?? #tDy # ## #   KA!A#a%ys   &A> >Bc                 ,    | j         | j        n| j         S r)   )_num2r   r*   s    r   r   zSubplotSpec.num2W  s     J.tyyDJ>r   c                     || _         d S r)   )r
  )r   values     r   r   zSubplotSpec.num2[  s    


r   c                     | j         S r)   )r   r*   s    r   rq   zSubplotSpec.get_gridspec_  s
    ~r   c                 t    |                                                                  \  }}||| j        | j        fS )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``).
        )rq   r0   r   r   )r   r  r  s      r   r0   zSubplotSpec.get_geometryb  s8     &&((5577
dT49di//r   c                 z    |                                  j        }t          | j        |z  | j        |z  dz             S )z6The rows spanned by this subplot, as a `range` object.r   )rq   r   r   r   r   )r   r   s     r   r7   zSubplotSpec.rowspanm  s;     !!##)TY%'e);a)?@@@r   c                     |                                  j        }t          | j        |z  | j        |z  g          \  }}t          ||dz             S )z9The columns spanned by this subplot, as a `range` object.r   )rq   r   sortedr   r   r   )r   r   c1c2s       r   r8   zSubplotSpec.colspans  sR     !!##) U*DI,=>??BRa   r   c                 "    | j         j        dk    S Nr   )r7   r   r*   s    r   is_first_rowzSubplotSpec.is_first_row|      |!Q&&r   c                 P    | j         j        |                                 j        k    S r)   )r7   r   rq   r   r*   s    r   is_last_rowzSubplotSpec.is_last_row  !    | D$5$5$7$7$===r   c                 "    | j         j        dk    S r  )r8   r   r*   s    r   is_first_colzSubplotSpec.is_first_col  r  r   c                 P    | j         j        |                                 j        k    S r)   )r8   r   rq   r   r*   s    r   is_last_colzSubplotSpec.is_last_col  r  r   c                    |                                  }|                                \  }}t          j        | j        | j        g||f          \  }}|                    |          \  }}}	}
||                                         }||                                         }|	|                                         }|
|                                         }t          j
        ||||          S )zJ
        Update the subplot position from ``figure.subplotpars``.
        )rq   r0   rT   unravel_indexr   r   rl   minmaxr   from_extents)r   r3   r   r   r   r  r  ri   rh   rj   rk   
fig_bottomfig_topfig_left	fig_rights                  r   r   zSubplotSpec.get_position  s     $$&&,,..u%ty$)&<uenMM
d''// 	5Xy* !&**,,
4.$$&&T?&&((t$((**	 :y'JJJr   c                 v    |                                  }t          |d          r|                                S | S )zX
        Return the topmost `SubplotSpec` instance associated with the subplot.
        rn   )rq   rr   rn   )r   r   s     r   rn   z#SubplotSpec.get_topmost_subplotspec  s?     $$&&8677 	33555Kr   c           	          | j         | j        | j        ft          |dt	                                t          |dt	                                t          |dt	                                fk    S )z}
        Two SubplotSpecs are considered equal if they refer to the same
        position(s) in the same `GridSpec`.
        r   r   r   )r   r   r   r   r   )r   others     r   __eq__zSubplotSpec.__eq__  s\     DI6E;99E668844E66884466 	7r   c                 D    t          | j        | j        | j        f          S r)   )hashr   r   r   r*   s    r   __hash__zSubplotSpec.__hash__  s    T^TY	:;;;r   c                      t          ||| fi |S )a  
        Create a GridSpec within this subplot.

        The created `.GridSpecFromSubplotSpec` will have this `SubplotSpec` as
        a parent.

        Parameters
        ----------
        nrows : int
            Number of rows in grid.

        ncols : int
            Number of columns in grid.

        Returns
        -------
        `.GridSpecFromSubplotSpec`

        Other Parameters
        ----------------
        **kwargs
            All other parameters are passed to `.GridSpecFromSubplotSpec`.

        See Also
        --------
        matplotlib.pyplot.subplots

        Examples
        --------
        Adding three subplots in the space occupied by a single subplot::

            fig = plt.figure()
            gs0 = fig.add_gridspec(3, 1)
            ax1 = fig.add_subplot(gs0[0])
            ax2 = fig.add_subplot(gs0[1])
            gssub = gs0[2].subgridspec(1, 3)
            for i in range(3):
                fig.add_subplot(gssub[0, i])
        )r   )r   r   r   r   s       r   subgridspeczSubplotSpec.subgridspec  s    P 'ueTDDVDDDr   r)   )r$   r   r   r   r   r'   r   r  r   r   setterrq   r0   r7   r8   r  r  r  r  r   rn   r+  r.  r0  r2   r   r   r   r   	  s{        &   
> > >
 * * \*^ ? ? X? 
[  [  	0 	0 	0 A A XA
 ! ! X!' ' '> > >' ' '> > >K K K   	7 	7 	7< < <(E (E (E (E (Er   r   c                   *    e Zd ZdZ	 	 ddZ	 	 ddZdS )r   zM
    Parameters defining the positioning of a subplots grid in a figure.
    Nc                     dD ]&}t          | |t          j        d|                     '|                     ||||||           dS )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.
        r   r   N)r   r   r   r   )r   rM   rO   rN   rP   rQ   rR   r|   s           r   r   zSubplotParams.__init__  s]    4 J 	F 	FCD#s|,Cc,C,CDEEEED&%ff=====r   c                    ||n| j         ||n| j        k    rt          d          ||n| j        ||n| j        k    rt          d          ||| _         ||| _        ||| _        ||| _        ||| _        |	|| _        dS dS )zY
        Update the dimensions of the passed parameters. *None* means unchanged.
        Nzleft cannot be >= rightzbottom cannot be >= top)rM   rN   r   rO   rP   rQ   rR   )r   rM   rO   rN   rP   rQ   rR   s          r   r   zSubplotParams.update  s    
 %TT49".EEDJ@ @6777)VVt{?CC: :6777DIDJ DK?DH DK DKKK r   )NNNNNN)r$   r   r   r   r   r   r2   r   r   r   r     sY          @D%)> > > >< >B#'! ! ! ! ! !r   r   )r   r   loggingnumbersr   numpyrT   
matplotlibr   r   r   r   matplotlib.transformsr   	getLoggerr$   _logr	   rs   r   r   r   r2   r   r   <module>r<     s  
 
                 : : : : : : : : : : & & & & & &w""R R R R R R R Rj[" [" [" [" ["| [" [" ["|9< 9< 9< 9< 9<l 9< 9< 9<xOE OE OE OE OE OE OE OEd9! 9! 9! 9! 9! 9! 9! 9! 9! 9!r   