a
    ضa                     @   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   Z_from_subplot_args)selfZfigargskwargs r   i/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/matplotlib/axes/_subplots.pyr
      s    zSubplotBase.__init__z3.4get_subplotspecz1(get_subplotspec returns a SubplotSpec instance.))alternativeZaddendumc                 C   s"   |    \}}}}|||d fS )z*Get the subplot geometry, e.g., (2, 2, 3).r   )r   get_geometry)r   rowscolsZnum1Z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_paramsZset_positionfigbox)r   ZnumrowsZ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   Z_set_positionget_positionr   )r   Z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   s
   |   jS r   )r   nrowsr   r   r   r   numRowsI   s    zSubplotBase.numRowszget_gridspec().ncolsc                 C   s
   |   jS r   )r   ncolsr   r   r   r   numColsN   s    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   s   |   jjdkS Nr   )r   rowspanstartr   r   r   r   is_first_rowY   s    zSubplotBase.is_first_rowz"ax.get_subplotspec().is_last_row()c                 C   s   |   jj|  jkS r   )r   r%   stopr   r    r   r   r   r   is_last_row]   s    zSubplotBase.is_last_rowz#ax.get_subplotspec().is_first_col()c                 C   s   |   jjdkS r$   )r   colspanr&   r   r   r   r   is_first_cola   s    zSubplotBase.is_first_colz"ax.get_subplotspec().is_last_col()c                 C   s   |   jj|  jkS r   )r   r*   r(   r   r"   r   r   r   r   is_last_cole   s    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   s   |rt | jtjjsd S |  }| j }| sv|dkrD| 	d | jj
ddd | jj d dkrv| jjd | s|dkr| 	d | jj
ddd | jj d d	kr| jjd d S )
Ntop bothF)whichZlabeltopr   Zbottom)r4   Zlabelbottomr   )
isinstancepatchmplpatches	Rectangler   Zxaxisget_label_positionr'   Z
set_xlabelset_tick_params
offsetTextr   set_visibler)   r   r-   ssZlabel_positionr   r   r   r.   t   s     


zSubplotBase._label_outer_xaxisc                C   s   |rt | jtjjsd S |  }| j }| sv|dkrD| 	d | jj
ddd | jj d dkrv| jjd | s|dkr| 	d | jj
ddd | jj d d	kr| jjd d S )
Nleftr2   r3   F)r4   Z	labelleftr   right)r4   Z
labelrightr   )r5   r6   r7   r8   r9   r   Zyaxisr:   r+   Z
set_ylabelr;   r<   r   r=   r,   r>   r   r   r   r/      s     


zSubplotBase._label_outer_yaxisc                 O   st   d|v r0d|v r0|d | ur0|d | ur0t d| jj|  g|R i |}| d |d | j| | |S )z<Make a twinx axes of self. This is used for twinx and twiny.ZsharexZshareyz$Twinned Axes may share only one axisZdatalim)
ValueErrorr   Zadd_subplotr   Zset_adjustableZ_twinned_axesjoin)r   r   r   Z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   r'   r)   r+   r,   r0   r.   r/   rD   r   r   r   r   r      sJ   






r   z	{}Subplotr	   )Z
matplotlibr7   r   r   Zmatplotlib.axes._axesr   Zmatplotlib.gridspecr   r   r   Z_make_class_factoryZsubplot_class_factoryZSubplotr   r   r   r   <module>   s    "