
    G8cT                        d dl m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mZmZ ddlmZ d Z G d	 d
      Z ej$                  d       G d dee             Z ej(                  ed      Z G d d      Z G d de      ZeZy)    )NumberN)_apicbook)SubplotSpec   )SizeSubplotDividerDivider)Axesc                     | }| }| j                   d   j                  ||       | j                   d   j                  ||       y )Nbottom
ticklabelslabelleft)axistoggle)ax	bottom_onleft_on
bottom_offleft_offs        C/usr/lib/python3/dist-packages/mpl_toolkits/axes_grid1/axes_grid.py
_tick_onlyr      sG    J{HGGH
*EGGFOhh?    c                   :     e Zd Z fdZdddZd Z fdZ xZS )CbarAxesBasec                @    || _         d | _        t        |   |i | y N)orientation_locatorsuper__init__)selfr    argskwargs	__class__s       r   r#   zCbarAxesBase.__init__   s$    &$)&)r   N)ticksc                l    | j                   dv rdnd} | j                  j                  |f| ||d|}|S )Ntopr   
horizontalvertical)caxr    r(   )r    figurecolorbar)r$   mappabler(   r&   r    cbs         r   r0   zCbarAxesBase.colorbar   sN     ,,0AAL 	 "T[[!!( 9+(-9179	r   c                 \    | j                   | j                     }|j                  ||       y )Nr   )r   r    r   )r$   br   s      r   toggle_labelzCbarAxesBase.toggle_label"   s&    yy))*q*r   c                 H    | j                   }t        | 	          || _         y r   )r    r"   cla)r$   r    r'   s     r   r7   zCbarAxesBase.cla&   s    &&&r   )__name__
__module____qualname__r#   r0   r5   r7   __classcell__r'   s   @r   r   r      s!    *
 +/ +' 'r   r   3.5c                       e Zd Zy)CbarAxesN)r8   r9   r:    r   r   r?   r?   ,   s    r   r?   zCbar{}c                       e Zd ZdZeZ	 	 	 dddddddddZd Zd	 Zd
 Z	d Z
d Zd Zd Zd Zd Zd Zd Zd Zd Z ej*                  d      d        Zy)Gridaq  
    A grid of Axes.

    In Matplotlib, the Axes location (and size) is specified in normalized
    figure coordinates. This may not be ideal for images that needs to be
    displayed with a given aspect ratio; for example, it is difficult to
    display multiple images of a same size with some fixed padding between
    them.  AxesGrid can be used in such case.
    NFTL)	share_allshare_xshare_y
label_mode
axes_classaspectc                   |\  | _         | _        || j                   | j                  z  }n9d|cxk  r&| j                   | j                  z  k  st        d       t        d      || _        t	        t
        j                  t        j                  |d            \  | _	        | _
        t        j                  ddg|       || _        || j                  }n1t        |t         t"        f      r|\  }}t%        j&                  |fi |}t)        g g |      }t        |t*        t,        t.        f      rt1        ||fi || _        nOt5        |      d	k(  rt1        |g|i || _        n,t5        |      d
k(  rt7        ||fi || _        nt9        d      | j2                  j;                         }t        j<                  | j                   | j                  fdt>              }tA        | j                        D ]G  }| jC                  |      \  }}|r|d   x}}n|r|d|f   nd}|	r||df   nd} |||||      |||f<   I |jE                  | j                  dk(  rdnd      jG                         | _$        |jJ                  jG                         | _&        |jG                         | _'        | jL                  d   d   | _(        | jS                          | jH                  D ]  }|jU                  |        | jW                  |
       y)a3  
        Parameters
        ----------
        fig : `.Figure`
            The parent figure.
        rect : (float, float, float, float) or int
            The axes position, as a ``(left, bottom, width, height)`` tuple or
            as a three-digit subplot position code (e.g., "121").
        nrows_ncols : (int, int)
            Number of rows and columns in the grid.
        ngrids : int or None, default: None
            If not None, only the first *ngrids* axes in the grid are created.
        direction : {"row", "column"}, default: "row"
            Whether axes are created in row-major ("row by row") or
            column-major order ("column by column").  This also affects the
            order in which axes are accessed using indexing (``grid[index]``).
        axes_pad : float or (float, float), default: 0.02
            Padding or (horizontal padding, vertical padding) between axes, in
            inches.
        share_all : bool, default: False
            Whether all axes share their x- and y-axis.  Overrides *share_x*
            and *share_y*.
        share_x : bool, default: True
            Whether all axes of a column share their x-axis.
        share_y : bool, default: True
            Whether all axes of a row share their y-axis.
        label_mode : {"L", "1", "all"}, default: "L"
            Determines which axes will get tick labels:

            - "L": All axes on the left column get vertical tick labels;
              all axes on the bottom row get horizontal tick labels.
            - "1": Only the bottom left axes is labelled.
            - "all": all axes are labelled.

        axes_class : subclass of `matplotlib.axes.Axes`, default: None
        aspect : bool, default: False
            Whether the axes aspect ratio follows the aspect ratio of the data
            limits.
        Nr   z7ngrids must be positive and not larger than nrows*ncols   columnrow)	direction)r,   r-   rI         zIncorrect rect format)dtype)r   r   )sharexshareyCF)order),_nrows_ncols
ValueErrorngridsmapr   Fixednpbroadcast_to_horiz_pad_size_vert_pad_sizer   check_in_list
_direction_defaultAxesClass
isinstancelisttuple	functoolspartialdictstrr   r   r	   _dividerlenr
   	TypeErrorget_positionfullobjectrange_get_col_rowraveltolistaxes_allTaxes_columnaxes_rowaxes_llc_init_locatorsadd_axesset_label_mode)r$   figrectnrows_ncolsr[   rN   axes_padrD   rE   rF   rG   rH   rI   clsr&   kw
axes_arrayicolrM   rR   rS   r   s                          r   r#   zGrid.__init__A   s   j $/ T[>[[4;;.Fv:t{{!:: MO O ; MO O 47JJ!4561d1 	He,	B#//J
T5M2$KC"**39&9JR"V<dS&+67*3;;DMY!^*3<<<DMY!^#C44DM344}}))+WWdkk4;;7VL
t{{# 	9A((+HC",T"22/6AsF+D/6CF+D#-T&$9JsCx 	9 #((E1#s ) <<BFH 	%<<..0"))+((+B/-- 	BLL	 	J'r   c                 Z   g }g }t        | j                        D ]_  }|r|j                  | j                         |j                  t	        |             t        j                  d      }|j                  |       a g }g }t        | j                        D ]_  }|r|j                  | j                         |j                  t	        |             t        j                  d      }|j                  |       a t        | j                        D ]g  }| j                  |      \  }}	| j                  j                  ||   || j                  dz
  |	z
           }
| j                  |   j                  |
       i | j                  j                  |       | j                  j!                  |       y )Nr   nxny)rr   rY   appendr`   rm   r   ScaledrX   ra   r[   rs   rl   new_locatorrv   set_axes_locatorset_horizontalset_vertical)r$   hh_ax_pos_szvv_ax_posr   r   rM   locators              r   r{   zGrid._init_locators   sb   t{{# 	A--.OOCF#QBHHRL	 t{{# 	A,,-OOCF#QBHHRL	 t{{# 	7A((+HCmm//C=XdkkAo.C%D 0 FGMM!--g6		7 	$$Q'""1%r   c                     | j                   dk(  rt        || j                        \  }}||fS t        || j                        \  }}||fS )NrL   )rc   divmodrX   rY   )r$   nr   rM   s       r   rs   zGrid._get_col_row   sL    ??h&a-HC Cx a-HCCxr   c                 ,    t        | j                        S r   )rm   rv   r$   s    r   __len__zGrid.__len__   s    4==!!r   c                      | j                   |   S r   )rv   )r$   r   s     r   __getitem__zGrid.__getitem__   s    }}Qr   c                 2    | j                   | j                  fS )zV
        Return the number of rows and columns of the grid as (nrows, ncols).
        )rX   rY   r   s    r   get_geometryzGrid.get_geometry   s     {{DKK''r   c                 T    |d   | j                   _        |d   | j                  _        y)z
        Set the padding between the axes.

        Parameters
        ----------
        axes_pad : (float, float)
            The padding (horizontal pad, vertical pad) in inches.
        r   r   Nr`   
fixed_sizera   )r$   r   s     r   set_axes_padzGrid.set_axes_pad   s(     +31+')1!&r   c                 Z    | j                   j                  | j                  j                  fS )z
        Return the axes padding.

        Returns
        -------
        hpad, vpad
            Padding (horizontal pad, vertical pad) in inches.
        r   r   s    r   get_axes_padzGrid.get_axes_pad   s,     $$//##..0 	0r   c                 :    | j                   j                  |       y)z%Set the aspect of the SubplotDivider.N)rl   
set_aspect)r$   rI   s     r   r   zGrid.set_aspect   s      (r   c                 6    | j                   j                         S )z(Return the aspect of the SubplotDivider.)rl   
get_aspectr   s    r   r   zGrid.get_aspect   s    }}''))r   c                    |dk(  r| j                   D ]  }t        |dd        y|dk(  r| j                  d   dd D ]  }t        |dd        | j                  d   d   }t        |dd       | j                  d	d D ]-  }|dd D ]  }t        |dd        |d   }t        |dd       / y|d
k(  r:| j                   D ]  }t        |dd        | j                  }t        |dd       yy)a  
        Define which axes have tick labels.

        Parameters
        ----------
        mode : {"L", "1", "all"}
            The label mode:

            - "L": All axes on the left column get vertical tick labels;
              all axes on the bottom row get horizontal tick labels.
            - "1": Only the bottom left axes is labelled.
            - "all": all axes are labelled.
        allFrC   r   NrW   T)r   r   r   1)rv   r   rx   rz   )r$   moder   r   s       r   r}   zGrid.set_label_mode  s    5=mm -2ue,-S[&&q)#2. >2u=> !!!$R(BrUE:''+ >cr( ABrT4@A W2=> S[mm =2t<= BrUE: r   c                     | j                   S r   )rl   r   s    r   get_dividerzGrid.get_divider+  s    }}r   c                 :    | j                   j                  |       y r   )rl   set_locator)r$   r   s     r   r   zGrid.set_axes_locator.  s    !!'*r   c                 6    | j                   j                         S r   )rl   get_locatorr   s    r   get_axes_locatorzGrid.get_axes_locator1  s    }}((**r   r=   c                 6    | j                   j                         S r   )rl   get_vsize_hsizer   s    r   r   zGrid.get_vsize_hsize4  s    }},,..r   NrM   g{Gz?)r8   r9   r:   __doc__r   rd   r#   r{   rs   r   r   r   r   r   r   r   r}   r   r   r   r   
deprecatedr   r@   r   r   rB   rB   4   s     
  m( ! m(^&:" (
5
0)*';R++ T__U/ /r   rB   c                   B     e Zd Z	 	 	 d
dddddddddd	 fdZd	 Z xZS )	ImageGridNFTrC   rightz5%)	rD   rI   rG   	cbar_modecbar_locationcbar_pad	cbar_sizecbar_set_caxrH   c       	            t        j                  g d|
       t        j                  g d|       |
| _        || _        || _        || _        t        |   |||||||dd||	|       | j                  D ]  }|j                  |        |r| j                  dk(  r&| j                  D ]  }| j                  d   |_         y| j                  d	k(  rit        | j                        D ]P  \  }}| j                  |      \  }}| j                  d
v r| j                  |   |_        =| j                  |   |_        R yt        | j                  | j                        D ]  \  }}||_         yy)a`	  
        Parameters
        ----------
        fig : `.Figure`
            The parent figure.
        rect : (float, float, float, float) or int
            The axes position, as a ``(left, bottom, width, height)`` tuple or
            as a three-digit subplot position code (e.g., "121").
        nrows_ncols : (int, int)
            Number of rows and columns in the grid.
        ngrids : int or None, default: None
            If not None, only the first *ngrids* axes in the grid are created.
        direction : {"row", "column"}, default: "row"
            Whether axes are created in row-major ("row by row") or
            column-major order ("column by column").  This also affects the
            order in which axes are accessed using indexing (``grid[index]``).
        axes_pad : float or (float, float), default: 0.02in
            Padding or (horizontal padding, vertical padding) between axes, in
            inches.
        share_all : bool, default: False
            Whether all axes share their x- and y-axis.
        aspect : bool, default: True
            Whether the axes aspect ratio follows the aspect ratio of the data
            limits.
        label_mode : {"L", "1", "all"}, default: "L"
            Determines which axes will get tick labels:

            - "L": All axes on the left column get vertical tick labels;
              all axes on the bottom row get horizontal tick labels.
            - "1": Only the bottom left axes is labelled.
            - "all": all axes are labelled.

        cbar_mode : {"each", "single", "edge", None}, default: None
            Whether to create a colorbar for "each" axes, a "single" colorbar
            for the entire grid, colorbars only for axes on the "edge"
            determined by *cbar_location*, or no colorbars.  The colorbars are
            stored in the :attr:`cbar_axes` attribute.
        cbar_location : {"left", "right", "bottom", "top"}, default: "right"
        cbar_pad : float, default: None
            Padding between the image axes and the colorbar axes.
        cbar_size : size specification (see `.Size.from_any`), default: "5%"
            Colorbar size.
        cbar_set_cax : bool, default: True
            If True, each axes in the grid has a *cax* attribute that is bound
            to associated *cbar_axes*.
        axes_class : subclass of `matplotlib.axes.Axes`, default: None
        )eachsingleedgeN)r   )r   r   r   r+   )r   T)rN   r   rD   rE   rF   rI   rG   rH   r   r   r   r   r   N)r   rb   _colorbar_mode_colorbar_location_colorbar_pad_colorbar_sizer"   r#   	cbar_axesr|   rv   r.   	enumeraters   zip)r$   r~   r   r   r[   rN   r   rD   rI   rG   r   r   r   r   r   rH   r   indexr   rM   r.   r'   s                        r   r#   zImageGrid.__init__<  sr   @ 	;%.	0=)6	8'"/%' 	{F(tF!j	 	 	: .. 	BLL	 ""h.-- /B!^^A.BF/$$.!*4==!9 5IE2#007HC..2CC!%!4!%!45  #4==$..A !GB BF! r   c                    | j                   E| j                  dv r| j                  j                  | _         n| j                  j                  | _         t        | j                        D cg c]Y  } t        | j                        | j                  d   j                  | j                  j                         | j                        [ c}| _        | j                  }| j                  }g }g }g }g }|dk(  r|dv r|dk(  r| j                  t!        j"                  | j$                        z  }|j'                  t!        j(                  | j*                  |             |j'                  t!        j(                  | j                   |             | j                  j-                  ddd      }	n|d	k(  r| j.                  t!        j0                  | j$                        z  }|j'                  t!        j(                  | j*                  |             |j'                  t!        j(                  | j                   |             | j                  j-                  ddd
      }	t        | j                        D ]   }
| j                  |
   j3                  d       " | j                  d   j5                  	       | j                  d   j3                  d       t7        | j8                  d         D ]  \  }}|r|j'                  | j                         |r&t!        j"                  |d| j                  d         }n2t!        j"                  | j                  d   d| j                  d         }|dk(  r|dk(  s
|dk(  r}|dk(  rx|j'                  t;        |             |j'                  t!        j(                  | j*                  |             |j'                  t!        j(                  | j                   |             |j'                  t;        |             |j'                  |       |dk(  s<|dk(  s|dk(  sH|| j.                  dz
  k(  s\|j'                  t!        j(                  | j                   |             |j'                  t;        |             |j'                  t!        j(                  | j*                  |              g }g }t7        | j<                  d   d d d         D ]  \  }}|r|j'                  | j                         |r&t!        j0                  |d| j                  d         }n2t!        j0                  | j                  d   d| j                  d         }|d	k(  r|dk(  s
|dk(  r}|dk(  rx|j'                  t;        |             |j'                  t!        j(                  | j*                  |             |j'                  t!        j(                  | j                   |             |j'                  t;        |             |j'                  |       |dk(  s<|dk(  s|dk(  sH|| j                  dz
  k(  s\|j'                  t!        j(                  | j                   |             |j'                  t;        |             |j'                  t!        j(                  | j*                  |              t        | j                        D ]  }
| j?                  |
      \  }}| j                  j-                  ||   || j                  dz
  |z
           }	| j                  |
   j5                  |	       |dk(  r|dv r4| j                  j-                  ||   || j                  dz
  |z
           }	n7|dv r3| j                  j-                  ||   || j                  dz
  |z
           }	| j                  |
   j5                  |	       |dk(  s|dk(  r|dk(  s|dk(  re|| j.                  dz
  k(  rS| j                  j-                  |d   || j                  dz
  |z
           }	| j                  |   j5                  |	       w|d	k(  r|| j                  dz
  k(  s|dk(  s|dk(  s| j                  j-                  ||   |d         }	| j                  |   j5                  |	        |dk(  r|dk(  r| j                  t!        j"                  | j$                        z  }|j'                  t!        j(                  | j                   |             |j'                  t!        j(                  | j*                  |             | j                  j-                  ddd      }	n|dk(  r| j.                  t!        j0                  | j$                        z  }|j'                  t!        j(                  | j                   |             |j'                  t!        j(                  | j*                  |             | j                  j-                  ddd
      }	|dv rt        | j                        D ]   }
| j                  |
   j3                  d       " | j                  d   j5                  	       | j                  d   j3                  d       n%|dk(  r9t        | j                        D ]   }
| j                  |
   j3                  d       " n|dk(  r|dv r| j                  }n| j.                  }t        |      D ]   }
| j                  |
   j3                  d       " t        
dz   | j                        D ]   }| j                  |   j3                  d       " nZt        | j                        D ]B  }
| j                  |
   j3                  d       | j                  |
   jA                  g dd       D | j                  jC                  |       | j                  jE                  |       y c c}w )Nr   r   )r    r   )r   r   r   rW   )r   r   ny1r   )r   nx1r   FTaxes)rI   ref_axr   r   r   r   r+   r   )r   r   r*   )r   r+   )      ?r   MbP?r   active)which)#r   r   r`   r   ra   rr   r[   _cbaraxes_class_factoryrd   rv   r/   rl   ro   r   r   rX   r   AxesXrz   r   from_anyr   r   rY   AxesYset_visibler   r   ry   rm   rx   rs   set_positionr   r   )r$   r   cb_modecb_locationr   r   r   h_cb_posr   r   r   r   r   r   v_cb_posrM   countjs                     r   r{   zImageGrid._init_locators  s	    %&&*;;%)%9%9%D%D"%)%8%8%C%C"
 4;;'	)  <#D$:$:;a '')C)C)E 335) %%--h;2D#Df$[[4::dmm#<<t':':B?@t'9'92>?--33qQB3G([[4::dmm#<<t':':B?@t'9'92>?--33qbQ3G4;;' 5q!--e45NN1..w7NN1))$/ q!12 	AGC--.ZZ6$--:JKZZa 0'-dmmA6FH v% F*$.3!8A't':':B?@t'9'92>?OOCF#HHRLw& F*$.3$++/3It'9'92>?A't':':B?@3	A6  !1!1!!4TrT!:; 	AGC,,-ZZ6$--:JKZZa 0'-dmmA6FH x' F*$.3!8A't':':B?@t'9'92>?OOCF#HHRLu$ F*$.3$++/3It'9'92>?A't':':B?@3	A6 t{{# 	BA((+HCmm//8C=3;DKKM#<M3N 0 PGMM!--g6& "33"mm77#C=XdkkAo6K-L 8 NG !$55"mm77#C=XdkkAo6K-L 8 NG q!227;F"6)cQh&'1cT[[1_6L"mm77#A;8DKK!Oc4I+J 8 LGNN3'88A!X-#q2H$-#("mm778C=;CA; 8 HGNN3'88A5	B8 hg%[[4::dmm#<<t'9'92>?t':':B?@--33raR3H%[[4::dmm#<<t'9'92>?t':':B?@--33qbR3H..t{{+ 9ANN1%11%89q!227;q!--d34;;' 4q!--d34//5\ 4q!--d341q5$++. 5q!--e45 4;;' ?q!--e4q!../E5= / ??
 	$$Q'""1%k)s   )Aor   )r8   r9   r:   r#   r{   r;   r<   s   @r   r   r   9  s>      `! !&" `!D^&r   r   )numbersr   rh   numpyr^   
matplotlibr   r   matplotlib.gridspecr   axes_dividerr   r	   r
   mpl_axesr   r   r   r   r?   _make_class_factoryr   rB   r   AxesGridr@   r   r   <module>r      s       " + 7 7 @' '0 	|T 	 	 4%33L(K B/ B/JC& C&L r   