o
    i%                     @   s   d dl Z d dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ G dd dZi Ze ddddZee	Zd	d
 Zejjee	d ee	j ejjee	d dS )    N)cbook	docstring)Axes)GridSpecSubplotSpecc                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Z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dd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(S ))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   s   || _ t||| _|   | jj| || jfi | | jjdu r)d| _d| _	dS | jjj
d }|t  }tj| jj|| d| _tj| j| jj
d dd| d| _	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.
        Nz.ax)parentnameartistz.posT)r   r	   possubplotr
   )figurer   _from_subplot_args_subplotspecupdate_params_axes_class__init__figbox
_layoutbox_poslayoutboxr	   	layoutboxseq_id	LayoutBox)selffigargskwargsr	    r   T/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/matplotlib/axes/_subplots.pyr      s&   

zSubplotBase.__init__c                 C   s(   t dd t| jD }t|f|  fS )Nc                 s   s(    | ]}t |trt |ts|V  qd S N)
issubclassr   r   ).0cr   r   r   	<genexpr>?   s    
z)SubplotBase.__reduce__.<locals>.<genexpr>)nexttype__mro__$_picklable_subplot_class_constructor__getstate__)r   
axes_classr   r   r   
__reduce__=   s   zSubplotBase.__reduce__c                 C   s"   |    \}}}}|||d fS )z*Get the subplot geometry, e.g., (2, 2, 3).   )get_subplotspecget_geometry)r   rowscolsnum1num2r   r   r   r-   F   s   zSubplotBase.get_geometryc                 C   s2   t ||| jd|d  | _|   | | j dS )z;Change subplot geometry, e.g., from (1, 1, 1) to (2, 2, 3).)r   r+   N)r   r   r   r   set_positionr   )r   numrowsnumcolsnumr   r   r   change_geometryL   s   zSubplotBase.change_geometryc                 C   s   | j S )z?Return the `.SubplotSpec` instance associated with the subplot.r   r   r   r   r   r,   S   s   zSubplotBase.get_subplotspecc                 C   s
   || _ dS )z=Set the `.SubplotSpec`. instance associated with the subplot.Nr7   )r   subplotspecr   r   r   set_subplotspecW      
zSubplotBase.set_subplotspecc                 C   s
   | j  S )z<Return the `.GridSpec` instance associated with the subplot.)r   get_gridspecr8   r   r   r   r<   [   r;   zSubplotBase.get_gridspecc                 C   s(   |   j| jdd\| _}}| _| _dS )z=Update the subplot position from ``self.figure.subplotpars``.T)
return_allN)r,   get_positionr   r   numRowsnumCols)r   _r   r   r   r   _   s   zSubplotBase.update_paramsz3.2z"ax.get_subplotspec().rowspan.start)alternativec                 C      |   jjS r   r,   rowspanstartr8   r   r   r   rowNume      zSubplotBase.rowNumz"ax.get_subplotspec().colspan.startc                 C   rC   r   r,   colspanrF   r8   r   r   r   colNumj   rH   zSubplotBase.colNumc                 C      |   jjdkS Nr   rD   r8   r   r   r   is_first_rowo      zSubplotBase.is_first_rowc                 C      |   jj|  jkS r   )r,   rE   stopr<   nrowsr8   r   r   r   is_last_rowr      zSubplotBase.is_last_rowc                 C   rL   rM   rI   r8   r   r   r   is_first_colu   rO   zSubplotBase.is_first_colc                 C   rP   r   )r,   rJ   rQ   r<   ncolsr8   r   r   r   is_last_colx   rT   zSubplotBase.is_last_colc                 C   s   |   }|  }|s&| jddD ]}|d q|   d | d |sF| jddD ]}|d q.|   d | 	d dS dS )z
        Only show "outer" labels and tick labels.

        x-labels are only kept for subplots on the last row; y-labels only for
        subplots on the first column.
        both)whichF N)
rS   rU   get_xticklabelsset_visible	get_xaxisget_offset_text
set_xlabelget_yticklabels	get_yaxis
set_ylabel)r   lastrowfirstcollabelr   r   r   label_outer{   s   
zSubplotBase.label_outerc                 O   s   d|v rd|v r|d | ur|d | urt dtt }|d|}| jj|  g|R d|i|}||ur>|| | 	d |	d | j
dur`|j
dur`|j
| j
 |j| j | j| | |S )z<Make a twinx axes of self. This is used for twinx and twiny.sharexshareyz$Twinned Axes may share only one axisre   datalimN)
ValueErrorstruuiduuid4popr   add_subplotr,   	set_labelset_adjustabler   constrain_samer   _twinned_axesjoin)r   r   r   sentinel
real_labeltwinr   r   r   _make_twin_axes   s.   


zSubplotBase._make_twin_axesc                 C   s   g }|   r|d|   g7 }g }dD ]}| j|d}|r(||d| q|r7|dd| d g7 }|  rE|d|  g7 }|  rS|d	|  g7 }d
| jj dd| d S )Nzlabel=)leftcenterright)loc:ztitle={,}zxlabel=zylabel=<z, >)	get_label	get_titleappendrt   
get_xlabel
get_ylabel	__class____name__)r   fieldstitlesktitler   r   r   __repr__   s    zSubplotBase.__repr__N)r   
__module____qualname____doc__r   r*   r-   r6   r,   r:   r<   r   r   
deprecatedpropertyrG   rK   rN   rS   rU   rW   rf   rx   r   r   r   r   r   r      s.    +	r   c                    sd    du rt jddd t zt fddt D W S  ty1   td j t fd i Y S w )	aF  
    Make a new class that inherits from `.SubplotBase` and the
    given axes_class (which is assumed to be a subclass of `.axes.Axes`).
    This is perhaps a little bit roundabout to make a new class on
    the fly like this, but it means that a new Subplot class does
    not have to be created for every type of Axes.
    Nz3.3zSupport for passing None to subplot_class_factory is deprecated since %(since)s; explicitly pass the default Axes class instead. This will become an error %(removal)s.)messagec                 3   s"    | ]}|j t fkr|V  qd S r   )	__bases__r   )r!   clsr)   r   r   r#      s    z(subplot_class_factory.<locals>.<genexpr>z	%sSubplotr   )	r   warn_deprecatedr   r$   r   __subclasses__StopIterationr%   r   r   r   r   r   subplot_class_factory   s   	
r   c                 C   s   t | }||S )z
    Stub factory that returns an empty instance of the appropriate subplot
    class when called with an axes class. This is purely to allow pickling of
    Axes and Subplots.
    )r   __new__)r)   subplot_classr   r   r   r'      s   
r'   )Subplotr   )	functoolsrl   
matplotlibr   r   matplotlib.artistr
   martistmatplotlib.axes._axesr   matplotlib.gridspecr   r   matplotlib._layoutboxr   r   r   _subplot_classes	lru_cacher   r   r'   interpdupdatekwdocdedent_interpdr   r   r   r   r   <module>   s"     :
