o
    tBh                     @   s\   d dl Zd dl mZmZ d dlmZ d dlmZmZ G dd dZ	e
e	ddZeeZdS )	    N)_apicbook)Axes)GridSpecSubplotSpecc                   @   s6  e Zd ZdZdd Zejdddddd	 Zejdd
ddd Zdd Z	dd Z
dd Zejdddedd Zejdddedd Zejdddedd Zeddd Zejdddd d! Zejdd"dd#d$ Zejdd%dd&d' Zejdd(dd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3S )4SubplotBasez
    Base class for subplots, which are :class:`Axes` instances with
    additional methods to facilitate generating and manipulating a set
    of :class:`Axes` within a figure.
    c                 O   s2   | j j| |g dfi | | t|| dS )a  
        Parameters
        ----------
        fig : `matplotlib.figure.Figure`

        *args : tuple (*nrows*, *ncols*, *index*) or int
            The array of subplots in the figure has dimensions ``(nrows,
            ncols)``, and *index* is the index of the subplot being created.
            *index* starts at 1 in the upper left corner and increases to the
            right.

            If *nrows*, *ncols*, and *index* are all single digit numbers, then
            *args* can be passed as a single 3-digit number (e.g. 234 for
            (2, 3, 4)).

        **kwargs
            Keyword arguments are passed to the Axes (sub)class constructor.
        )r   r      r   N)_axes_class__init__set_subplotspecr   _from_subplot_args)selffigargskwargs r   p/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/matplotlib/axes/_subplots.pyr
      s   zSubplotBase.__init__z3.4get_subplotspecz1(get_subplotspec returns a SubplotSpec instance.))alternativeaddendumc                 C   s"   |    \}}}}|||d fS )z*Get the subplot geometry, e.g., (2, 2, 3).r   )r   get_geometry)r   rowscolsnum1num2r   r   r   r   &   s   zSubplotBase.get_geometryr   )r   c                 C   s2   t ||| jd|d  | _|   | | j dS )z;Change subplot geometry, e.g., from (1, 1, 1) to (2, 2, 3).)figurer   N)r   r   _subplotspecupdate_paramsset_positionfigbox)r   numrowsnumcolsnumr   r   r   change_geometry.   s   zSubplotBase.change_geometryc                 C   s   | j S )z?Return the `.SubplotSpec` instance associated with the subplot.)r   r   r   r   r   r   6   s   zSubplotBase.get_subplotspecc                 C   s   || _ | || j dS )z=Set the `.SubplotSpec`. instance associated with the subplot.N)r   _set_positionget_positionr   )r   subplotspecr   r   r   r   :   s   zSubplotBase.set_subplotspecc                 C   s
   | j  S )z<Return the `.GridSpec` instance associated with the subplot.)r   get_gridspecr$   r   r   r   r(   ?   s   
zSubplotBase.get_gridspeczget_position()c                 C   s   |   S N)r&   r$   r   r   r   r   C   s   zSubplotBase.figboxzget_gridspec().nrowsc                 C   
   |   jS r)   )r(   nrowsr$   r   r   r   numRowsI      
zSubplotBase.numRowszget_gridspec().ncolsc                 C   r*   r)   )r(   ncolsr$   r   r   r   numColsN   r-   zSubplotBase.numColsc                 C   s   dS )z=Update the subplot position from ``self.figure.subplotpars``.Nr   r$   r   r   r   r   S   s    zSubplotBase.update_paramsz#ax.get_subplotspec().is_first_row()c                 C      |   jjdkS Nr   )r   rowspanstartr$   r   r   r   is_first_rowY      zSubplotBase.is_first_rowz"ax.get_subplotspec().is_last_row()c                 C      |   jj|  jkS r)   )r   r2   stopr(   r+   r$   r   r   r   is_last_row]      zSubplotBase.is_last_rowz#ax.get_subplotspec().is_first_col()c                 C   r0   r1   )r   colspanr3   r$   r   r   r   is_first_cola   r5   zSubplotBase.is_first_colz"ax.get_subplotspec().is_last_col()c                 C   r6   r)   )r   r:   r7   r(   r.   r$   r   r   r   is_last_cole   r9   zSubplotBase.is_last_colc                 C   s   | j dd | jdd dS )a  
        Only show "outer" labels and tick labels.

        x-labels are only kept for subplots on the last row (or first row, if
        labels are on the top side); y-labels only for subplots on the first
        column (or last column, if labels are on the right side).
        F)check_patchN)_label_outer_xaxis_label_outer_yaxisr$   r   r   r   label_outeri   s   zSubplotBase.label_outerc                C      |rt | jtjjsd S |  }| j }| s;|dkr"| 	d | jj
ddd | jj d dkr;| jjd | sc|dkrH| 	d | jj
ddd | jj d d	kre| jjd d S d S d S )
Ntop bothF)whichlabeltopr   bottom)rE   labelbottomr   )
isinstancepatchmplpatches	Rectangler   xaxisget_label_positionr4   
set_xlabelset_tick_params
offsetTextr&   set_visibler8   r   r=   sslabel_positionr   r   r   r>   t   $   


zSubplotBase._label_outer_xaxisc                C   rA   )
NleftrC   rD   F)rE   	labelleftr   right)rE   
labelrightr   )rI   rJ   rK   rL   rM   r   yaxisrO   r;   
set_ylabelrQ   rR   r&   rS   r<   rT   r   r   r   r?      rW   zSubplotBase._label_outer_yaxisc                 O   st   d|v rd|v r|d | ur|d | urt d| jj|  g|R i |}| d |d | j| | |S )z<Make a twinx axes of self. This is used for twinx and twiny.sharexshareyz$Twinned Axes may share only one axisdatalim)
ValueErrorr   add_subplotr   set_adjustable_twinned_axesjoin)r   r   r   twinr   r   r   _make_twin_axes   s   

zSubplotBase._make_twin_axesN)__name__
__module____qualname____doc__r
   r   
deprecatedr   r#   r   r   r(   propertyr   r,   r/   r   r4   r8   r;   r<   r@   r>   r?   rg   r   r   r   r   r      sL    






r   z	{}Subplotr	   )
matplotlibrK   r   r   matplotlib.axes._axesr   matplotlib.gridspecr   r   r   _make_class_factorysubplot_class_factorySubplotr   r   r   r   <module>   s     "