a
    Sic7  ã                   @   sr   d Z 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d„Ze d	¡dd
d„ƒZddd„Zddd„ZdS )aü  
Routines to adjust subplot params so that subplots are
nicely fit in the figure. In doing so, only axis labels, tick labels, axes
titles and offsetboxes that are anchored to axes are currently considered.

Internally, this module assumes that the margins (left margin, etc.) which are
differences between ``Axes.get_tightbbox`` and ``Axes.bbox`` are independent of
Axes position. This may fail if ``Axes.adjustable`` is ``datalim`` as well as
such cases as when left or right margin are affected by xlabel.
é    N)Ú_apiÚartist)ÚFontProperties)ÚBboxçHáz®Gñ?c
           *      C   sn  |\}
}t tjd d ¡ d }|| }|dur8|| n|}|durL|| n|}t|ƒt|ƒkslt|ƒdkrpt‚|	du rŠd } } }}n,|	\}}}}|r¢d| nd}|r²d| nd}t |
d |f¡}t |
|d f¡}|du rðdd„ |D ƒ}t|||ƒD ]â\}}\}}t	d	d
„ |D ƒƒr qüg }|D ]"}| 
¡ r(|t ||¡g7 }q(t |¡}| j ¡  |¡}|||jf  |j|j 7  < |||jf  |j|j 7  < ||j|f  |j|j 7  < ||j|f  |j|j 7  < qü|  ¡ \} }!|sRt|dd…df  ¡ dƒ||   }| j}"|"rR|" ¡ rR| j ¡  |" |¡¡j}#||#||   7 }|szt|dd…df  ¡ dƒ||   }|sàt|ddd…f  ¡ dƒ||!  }| jrà| j ¡ rà| j ¡  | j |¡¡j}$||$||!  7 }|sFt|ddd…f  ¡ dƒ||!  }| j }"|"rF|" ¡ rF| j ¡  |" |¡¡j}$||$||!  7 }|| dkrbt! "d¡ dS || dkr~t! "d¡ dS t#|d| |d| d}%|dkr |dd…dd…f  ¡ ||   }&d| | |&|d   | }'|'dk rôt! "d¡ dS |&|' |%d< |
dkrj|dd…dd…f  ¡ ||!  }(d| | |(|
d   |
 })|)dk r^t! "d¡ dS |(|) |%d< |%S )a"  
    Return a dict of subplot parameters to adjust spacing between subplots
    or ``None`` if resulting axes would have zero height or width.

    Note that this function ignores geometry information of subplot itself, but
    uses what is given by the *shape* and *subplot_list* parameters.  Also, the
    results could be incorrect if some subplots have ``adjustable=datalim``.

    Parameters
    ----------
    shape : tuple[int, int]
        Number of rows and columns of the grid.
    span_pairs : list[tuple[slice, slice]]
        List of rowspans and colspans occupied by each subplot.
    subplot_list : list of subplots
        List of subplots that will be used to calculate optimal subplot_params.
    pad : float
        Padding between the figure edge and the edges of subplots, as a
        fraction of the font size.
    h_pad, w_pad : float
        Padding (height/width) between edges of adjacent subplots, as a
        fraction of the font size.  Defaults to *pad*.
    rect : tuple
        (left, bottom, right, top), default: None.
    z	font.size)ÚsizeéH   Nr   é   c                 S   s    g | ]}t  d d„ |D ƒ¡‘qS )c                 S   s   g | ]}|j d d‘qS )T)Úoriginal©Úget_position©Ú.0Úax© r   úT/var/www/html/django/DPS/env/lib/python3.9/site-packages/matplotlib/_tight_layout.pyÚ
<listcomp>G   ó    z7_auto_adjust_subplotpars.<locals>.<listcomp>.<listcomp>)r   Úunion)r   Úsubplotsr   r   r   r   F   s   ÿz,_auto_adjust_subplotpars.<locals>.<listcomp>c                 s   s   | ]}|  ¡  V  qd S ©N)Úget_visibler   r   r   r   Ú	<genexpr>L   r   z+_auto_adjust_subplotpars.<locals>.<genexpr>éÿÿÿÿzuTight layout not applied. The left and right margins cannot be made large enough to accommodate all axes decorations.zuTight layout not applied. The bottom and top margins cannot be made large enough to accommodate all axes decorations.)ÚleftÚrightÚbottomÚtopznTight layout not applied. tight_layout cannot make axes width small enough to accommodate all axes decorationsÚwspacezpTight layout not applied. tight_layout cannot make axes height small enough to accommodate all axes decorations.Úhspace)$r   ÚmplÚrcParamsÚget_size_in_pointsÚlenÚ
ValueErrorÚnpÚzerosÚzipÚallr   ÚmartistÚ_get_tightbbox_for_layout_onlyr   r   ÚtransFigureÚinvertedÚtransform_bboxÚstartÚxminÚstopÚxmaxÚymaxÚyminÚget_size_inchesÚmaxÚ
_supylabelÚget_in_layoutÚget_window_extentÚwidthÚ	_suptitleÚheightÚ
_supxlabelr   Úwarn_externalÚdict)*ÚfigÚrendererÚshapeÚ
span_pairsÚsubplot_listÚax_bbox_listÚpadÚh_padÚw_padÚrectÚrowsÚcolsZfont_size_inchZpad_inchZ	vpad_inchZ	hpad_inchZmargin_leftZmargin_bottomZmargin_rightZ
margin_topÚ_rightZ_topZvspacesZhspacesr   Zax_bboxÚrowspanÚcolspanÚbbr   Ztight_bbox_rawZ
tight_bboxZfig_width_inchZfig_height_inchZsuplabelZ	rel_widthZ
rel_heightÚkwargsr   Zh_axesÚvspaceZv_axesr   r   r   Ú_auto_adjust_subplotpars   s²    ÿÿþÿ

 "
ÿ""

ÿ"
ÿ

ý
 


 

rQ   z3.5c
                 C   sr   |\}
}g }|D ]F\}}|du r$|}|  t|| || d ƒt|| || d ƒf¡ qt| |||||||||	ƒ
S )a@  
    Return a dict of subplot parameters to adjust spacing between subplots
    or ``None`` if resulting axes would have zero height or width.

    Note that this function ignores geometry information of subplot
    itself, but uses what is given by the *nrows_ncols* and *num1num2_list*
    parameters.  Also, the results could be incorrect if some subplots have
    ``adjustable=datalim``.

    Parameters
    ----------
    nrows_ncols : tuple[int, int]
        Number of rows and number of columns of the grid.
    num1num2_list : list[tuple[int, int]]
        List of numbers specifying the area occupied by the subplot
    subplot_list : list of subplots
        List of subplots that will be used to calculate optimal subplot_params.
    pad : float
        Padding between the figure edge and the edges of subplots, as a
        fraction of the font size.
    h_pad, w_pad : float
        Padding (height/width) between edges of adjacent subplots, as a
        fraction of the font size.  Defaults to *pad*.
    rect : tuple
        (left, bottom, right, top), default: None.
    Nr	   )ÚappendÚslicerQ   )r?   r@   Znrows_ncolsZnum1num2_listrC   rD   rE   rF   rG   rH   ÚnrowsÚncolsrB   Ún1Ún2r   r   r   Úauto_adjust_subplotpars    s    ÿ

þrX   c                 C   s‚   g }| D ]t}|  ¡ }|du r |}t|dƒrn| ¡ }|durr| ¡ }| ¡ }|dur`||krld}qr| ¡ rrd}nd}| |¡ q|S )zþ
    Return a list of subplotspec from the given list of axes.

    For an instance of axes that does not support subplotspec, None is inserted
    in the list.

    If grid_spec is given, None is inserted for those not from the given
    grid_spec.
    NÚget_subplotspec)Úget_axes_locatorÚhasattrrY   Úget_topmost_subplotspecÚget_gridspecÚlocally_modified_subplot_paramsrR   )Ú	axes_listÚ	grid_specÚsubplotspec_listr   Zaxes_or_locatorÚsubplotspecÚgsr   r   r   Úget_subplotspec_listÊ   s$    

rd   c                    sø  dd„ |D ƒ}t ||ƒD ]\}	}
||
  |	¡ q| dd¡ |sDi S t| ¡ ƒ}‡ fdd„|D ƒ}tdd„ |D ƒƒ}tdd„ |D ƒƒ}g }|D ]ž}
|
 ¡  ¡ \}}t||ƒ\}}t||ƒ\}}|d	krØt	 
d
¡ i   S |d	kròt	 
d¡ i   S | t|
jj| |
jj| ƒt|
jj| |
jj| ƒf¡ qŽtˆ |||f||||||d	}|durô|durô|\}}}}|dur‚||d 7 }|dur˜||d 7 }|dur²|d|d  8 }|durÌ|d|d  8 }tˆ |||f||||||||||fd
}|S )a–  
    Return subplot parameters for tight-layouted-figure with specified padding.

    Parameters
    ----------
    fig : Figure
    axes_list : list of Axes
    subplotspec_list : list of `.SubplotSpec`
        The subplotspecs of each axes.
    renderer : renderer
    pad : float
        Padding between the figure edge and the edges of subplots, as a
        fraction of the font size.
    h_pad, w_pad : float
        Padding (height/width) between edges of adjacent subplots.  Defaults to
        *pad*.
    rect : tuple (left, bottom, right, top), default: None.
        rectangle in normalized figure coordinates
        that the whole subplots area (including labels) will fit into.
        Defaults to using the entire figure.

    Returns
    -------
    subplotspec or None
        subplotspec kwargs to be passed to `.Figure.subplots_adjust` or
        None if tight_layout could not be accomplished.
    c                 S   s   i | ]
}|g “qS r   r   ©r   Ússr   r   r   Ú
<dictcomp>  r   z+get_tight_layout_figure.<locals>.<dictcomp>Nc                    s   g | ]}|  ˆ ¡‘qS r   r   re   ©r?   r   r   r     r   z+get_tight_layout_figure.<locals>.<listcomp>c                 s   s   | ]}|  ¡ jV  qd S r   )r]   rT   re   r   r   r   r     r   z*get_tight_layout_figure.<locals>.<genexpr>c                 s   s   | ]}|  ¡ jV  qd S r   )r]   rU   re   r   r   r   r     r   r   zdtight_layout not applied: number of rows in subplot specifications must be multiples of one another.zgtight_layout not applied: number of columns in subplot specifications must be multiples of one another.)rA   rB   rC   rD   rE   rF   rG   r   r   r	   r   r   )rA   rB   rC   rD   rE   rF   rG   rH   )r'   rR   ÚpopÚlistÚvaluesr5   r]   Úget_geometryÚdivmodr   r=   rS   rL   r.   r0   rM   rQ   )r?   r_   ra   r@   rE   rF   rG   rH   Zss_to_subplotsr   rf   rC   rD   Z	max_nrowsZ	max_ncolsrB   rI   rJ   Zdiv_rowZmod_rowZdiv_colZmod_colrO   r   r   r   r   r   rh   r   Úget_tight_layout_figureì   sf     

þû	




úrn   )Nr   NNN)Nr   NNN)N)r   NNN)Ú__doc__Únumpyr%   Ú
matplotlibr    r   r   r)   Úmatplotlib.font_managerr   Úmatplotlib.transformsr   rQ   Ú
deprecatedrX   rd   rn   r   r   r   r   Ú<module>   s    þ
  þ)
# ÿ