
 m[c           @` s  d  Z  d d l m Z m Z m Z m Z d d l Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l j Z d d	 l m Z d d l j Z d d l j Z d d l j Z d d l  j! Z! d d l" j# Z# d d
 l  Td d l$ m% Z% m& Z& m' Z' m( Z( m) Z) m* Z* e j+ e,  Z- i e! j. d 6e! j. d 6e! j/ d 6e! j0 d 6e! j1 d 6e! j2 d 6e! j3 d 6e! j4 d 6e! j5 d 6e! j6 d 6e! j7 d 6e! j8 d 6e! j9 d 6e! j: d 6e! j; d 6e! j< d 6e! j= d 6e! j> d 6Z? e@ e?  ZA d d  ZB eC d   ZD d!   ZE d" e jF e jG f d#     YZH d$ eH f d%     YZI d& eI f d'     YZJ d( eI f d)     YZK d* eH f d+     YZL d, eH f d-     YZM eC d.  ZN eC eC eC eC eC d/ d0  ZO d1   ZP d2 d eQ d3  ZR d S(4   uS   
The image module supports basic image loading, rescaling and display
operations.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   urlparse(   t   urlopen(   t   BytesIO(   t   ceil(   t   rcParams(   t   allow_rasterization(   t   *(   t   Affine2Dt   BboxBaset   Bboxt   BboxTransformt   IdentityTransformt   TransformedBboxu   noneu   nearestu   bilinearu   bicubicu   spline16u   spline36u   hanningu   hammingu   hermiteu   kaiseru   quadricu   catromu   gaussianu   besselu   mitchellu   sincu   lanczosu   blackmang      ?c      
   C` s  t  |   d k r1 t j d d t j d d f Sg  } g  } x |  D] } | j | |  \ } } } }	 | d	 k	 rD | | 9} | | 9} | j | | | | j   p d f  | j t | | g | | j	 d | | j	 d g g   qD qD Wt  |  d k r t j d
 d t j d d f St j
 |  }
 t j t |
 j  t |
 j  d f d t j } xb | D]Z \ } } } } t   j | |
 j | |
 j  }	 t j | | |	 t j d t d | qiW| |
 j | |
 j | f S(   uD  
    Composite a number of RGBA images into one.  The images are
    composited in the order in which they appear in the `images` list.

    Parameters
    ----------
    images : list of Images
        Each must have a `make_image` method.  For each image,
        `can_composite` should return `True`, though this is not
        enforced by this function.  Each image must have a purely
        affine transformation with no shear.

    renderer : RendererBase instance

    magnification : float
        The additional magnification to apply for the renderer in use.

    Returns
    -------
    tuple : image, offset_x, offset_y
        Returns the tuple:

        - image: A numpy array of the same type as the input images.

        - offset_x, offset_y: The offset of the image (left, bottom)
          in the output figure.
    i    i   t   dtypeg      ?i   t   resamplet   alpha(   i    i    i   N(   i    i    i   (   t   lent   npt   emptyt   uint8t
   make_imaget   Nonet   appendt	   get_alphaR   t   shapet   uniont   zerost   intt   heightt   widthR   t	   translatet   x0t   y0t   _imageR   t   NEARESTt   False(   t   imagest   renderert   magnificationt   partst   bboxest   imaget   datat   xt   yt   transt   bboxt   outputR   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   composite_imagesA   s,    

%<-#c         ` s   t  d   | D  } | d k	 r( | n	  j   } | sA | rb x | D] } | j   qH Wn g     j         f d   } xM | D]E } t | t  r | j   r   j |  q |   | j   q W|   d S(   u  
    Draw a sorted list of artists, compositing images into a single
    image where possible.

    For internal matplotlib use only: It is here to reduce duplication
    between `Figure.draw` and `Axes.draw`, but otherwise should not be
    generally useful.
    c         s` s   |  ] } t  | t  Vq d  S(   N(   t
   isinstancet
   _ImageBase(   t   .0R/   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pys	   <genexpr>   s    c          ` s   t     d k r&   d j   n t     d k r t      \ }  } } |  j d k r  j   } | j  j  | j  j     j	 | t
 j |  t
 j |  |   | j   q n    2d  S(   Ni   i    (   R   t   drawR4   t   sizet   new_gct   set_clip_rectangleR2   t   set_clip_patht   get_clip_patht
   draw_imageR   t   roundt   restore(   R.   t   lt   bt   gc(   t   image_groupt   magt   parentR)   (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   flush_images   s    (N(	   t   anyR   t   option_image_nocompositeR8   t   get_image_magnificationR5   R6   t   can_compositeR   (   R)   RF   t   artistst   suppress_compositet
   has_imagest   not_compositet   aRG   (    (   RD   RE   RF   R)   s/   lib/python2.7/site-packages/matplotlib/image.pyt   _draw_list_compositing_images{   s    
c         C` s   t  j |  j d |  j d d f d |  j } |  | d d  d d  d d  f <| j t  j k r d | d d  d d  d f <n d | d d  d d  d f <| S(	   u\   
    Convert an RGB image to RGBA, as required by the image resample C++
    extension.
    i    i   i   R   Ni   i   g      ?(   R   R   R   R   R   (   t   At   rgba(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   _rgb_to_rgba   s    /%"R6   c           B` sp  e  Z d  Z e e j d  d     Z e e j d  d     Z e e j d d d d     Z d   Z	 e
 e
 e
 e
 d d	 e d
  Z d   Z d   Z d   Z d   Z d e e d  Z d e d  Z d   Z d   Z e 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$ RS("   i    u   2.1c         C` s   t  S(   N(   t	   _interpd_(   t   self(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   _interpd   s    c         C` s   d   t  j t  D S(   Nc         S` s   i  |  ] \ } } | |  q S(    (    (   R7   t   kt   v(    (    s/   lib/python2.7/site-packages/matplotlib/image.pys
   <dictcomp>   s   	 (   t   sixt	   iteritemsRU   (   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt	   _interpdr   s    t   alternativeu   mpl.image.interpolation_namesc         C` s   t  S(   N(   t   interpolations_names(   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt
   iterpnames   s    c         C` s   d t  |  j j j  S(   Nu   AxesImage(%g,%g;%gx%g)(   t   tuplet   axesR2   t   bounds(   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   __str__   s    i   g      @c	   
      K` s   t  j j |   t j j |  | |  t |  _ | d k rH t d } n  | |  _	 |  j
 |  |  j |  |  j |  |  j |  | |  _ d |  _ |  j |	  d S(   u  
        interpolation and cmap default to their rc settings

        cmap is a colors.Colormap instance
        norm is a colors.Normalize instance to map luminance to 0-1

        extent is data axes (left, right, bottom, top) for making image plots
        registered with data plots.  Default is to label the pixel
        centers with the zero-based row and column indices.

        Additional kwargs are matplotlib.artist properties

        u   image.originN(   t   martistt   Artistt   __init__t   cmt   ScalarMappablet   Truet
   _mouseoverR   R   t   origint   set_filternormt   set_filterradt   set_interpolationt   set_resampleRa   t   _imcachet   update(
   RV   t   axt   cmapt   normt   interpolationRk   t
   filternormt	   filterradR   t   kwargs(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRf      s    				c         C` s#   t  t |   j   } d  | d <| S(   Nu   _imcache(   t   superR6   t   __getstate__R   (   RV   t   state(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRz      s    
c         C` s,   |  j  d k r t d   n  |  j  j d  S(   u+   Get the numrows, numcols of the input imageu"   You must first set the image arrayi   N(   t   _AR   t   RuntimeErrorR   (   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   get_size   s    c         C` s    t  j j |  |  d |  _ d S(   uw   
        Set the alpha value used for blending - not supported on
        all backends

        ACCEPTS: float
        N(   Rd   Re   t	   set_alphaR   Rp   (   RV   R   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR      s    c         C` s&   d |  _ d |  _ t j j |   d S(   ub   
        Call this whenever the mappable is changed so observers can
        update state
        N(   R   Rp   t
   _rgbacacheRg   Rh   t   changed(   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR   
  s    		g      ?c   $   	   C` s  | d k r t d   n  | j d k r9 t d   n  t j | |  } | d k r[ d S| j | }	 | j | }
 |	 d k s |
 d k r d S|  j d k r t   j	 d | j
 d  j d d  } n	 t   } | t   j | j | j
 d | j | j
 d  j	 | j | j  |  j   7} | t   j	 | j | j  j | |  } | j r| r|	 d d k s|
 d d k rt t |	   } t t |
   } | |	 |	 } | |
 |
 } | t   j d | d |  7} n t |	  } t |
  } | s| j d k r.t d j | j
    n  | j d	 k rO| j } | j   } | j   } | t j j k rt j d  t j d  } } n  | j d k r| j } nC | j t j  | j t j  } | d k rt j } n	 t j  } t j! | j
 d | } | | (|  j" j# |  t j |  j" j$  t j |  j" j%  } |  j" j% | d	 } | t j k rpd n d } | | | } | | k  rd } n t j |  } | | | } | | k rd } n t j |  } | d k	 s| d k	 r
t j& | | |  } n  | | 8} t j' | j |   } t j' | j |   } | | k re| | | d } n  | d 7} t j( | | f d | j } t) j* | | | t+ |  j,   |  j-   d |  j.   pd |  j/   pd  ~ | d 8} | | k r| | | d 9} n  | | 7} t0 |  j" t1 j2  r9| j | j  } n  t j! | j
 d t j  } | j3 j
 | j
 k rt j4 | j3 t j  t j5  t j  d   | (n d | (t j( | | f d | j } t) j* | | | t+ |  j,   t6 d |  j.   pd |  j/   pd  ~ t j7 |  } t j8 |  } d | | <|  j" t j j9 | |   }  n | j
 d	 d
 k rqt: |  } n, | j
 d	 d k rt d | j
 f   n  t j( | | d f d | j }  |  j;   }! |! d k rd }! n  t) j* | |  | t+ |  j,   |  j-   |! |  j.   pd |  j/   p%d  |  j< |  d t6 d t= }  | j d	 k r|  j;   }! |! d k rtd }! n  |  d d  d d  d
 f }" t j> t j> |" t j   | |! t j?  |" (qn|  j@ d k r|  j< | d t6 d | j d	 k |  _@ n  |  j@ }  tA | | jB   jC    jB   }# |  t t |# jD d   t t |# jE d |  j
 d    t t |# jF d   t t |# jG d |  j
 d    f }  t   j	 t t |# jF d   t t |# jD d    | } |  | j | j | f S(   uM  
        Normalize, rescale and color the image `A` from the given
        in_bbox (in data space), to the given out_bbox (in pixel
        space) clipped to the given clip_bbox (also in pixel space),
        and magnified by the magnification factor.

        `A` may be a greyscale image (MxN) with a dtype of `float32`,
        `float64`, `uint16` or `uint8`, or an RGBA image (MxNx4) with
        a dtype of `float32`, `float64`, or `uint8`.

        If `unsampled` is True, the image will not be scaled, but an
        appropriate affine transformation will be returned instead.

        If `round_to_pixel_border` is True, the output image size will
        be rounded to the nearest pixel boundary.  This makes the
        images align correctly with the axes.  It should not be used
        in cases where you want exact scaling, however, such as
        FigureImage.

        Returns the resulting (image, x, y, trans), where (x, y) is
        the upper left corner of the result in pixel space, and
        `trans` is the affine transformation from the image to pixel
        space.
        u9   You must first set the image array or the image attributei    uk   _make_image must get a non-empty image. Your Artist's draw method must filter before this method is called.u   upperi   ig      ?g        i   i   u   Invalid dimensions, got {}u   fg    חAR   g    cAg     @g?g?i   u   Invalid dimensions, got %st   bytesRt   N(   Ni    i    N(   Ni    i    N(   i   i   (H   R   R}   R9   R   t   intersectionR!   R    Rk   R   R"   R   t   scaleR   R#   R$   t   get_transformt	   is_affineR   R   t   ndimt
   ValueErrort   formatR   t   mint   maxR   t   mat   maskedt   int32t   kindt   astypet   float64t   float32R   Rt   t   autoscale_Nonet   vmaxt   vmint   clipt   asscalarR   R%   R   RU   t   get_interpolationt   get_resamplet   get_filternormt   get_filterradR5   t   mcolorst   NoNormt   maskt   wheret   nanRi   t   arrayt   isnant   masked_arrayRT   R   t   to_rgbaR'   t   asarrayR   Rp   R   t   frozent   invertedt   ymint   ymaxt   xmint   xmax($   RV   RR   t   in_bboxt   out_bboxt	   clip_bboxR*   t	   unsampledt   round_to_pixel_bordert   clipped_bboxt   out_width_baset   out_height_baset   t0t   tt	   out_widtht
   out_heightt   extra_widtht   extra_heightt	   inp_dtypet   a_mint   a_maxt   scaled_dtypet   dat   A_scaledt   dvt   vmidt   factt   newmint   newmaxt   A_resampledR   t   out_maskt	   out_alphaR3   R   t   alpha_channelt   subset(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   _make_image  s   ,			 $	""				



	
!!	"	*	#*	4c         C` s   t  d   d  S(   Nu)   The make_image method must be overridden.(   R}   (   RV   R)   R*   R   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR   !  s    c         C` su   |  j  | d t \ } } } } | d k r1 d St   j | j d | j d  | } | j | | | | |  d S(   uu   
        draw unsampled image. The renderer should support a draw_image method
        with scale parameter.
        R   Ni   i    (   R   Ri   R   R   R   R   R>   (   RV   R)   RC   t   imRA   RB   R1   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   _draw_unsampled_image$  s
    !'c         C` s   t  S(   u{   
        return True if the image is better to be drawn unsampled.
        The derived class needs to override it.
        (   R'   (   RV   R)   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   _check_unsampled_image3  s    c   	      O` s  |  j    s t |  _ d  S|  j   j d k r; t |  _ d  S| j   } |  j |  | j |  j    | j	 |  j
    | j |  j    |  j |  r |  j   j r |  j | |  nI |  j | | j    \ } } } } | d  k	 r| j | | | |  n  | j   t |  _ d  S(   Ni    (   t   get_visibleR'   t   stalet	   get_arrayR9   R:   t   _set_gc_clipR   R   t   set_urlt   get_urlt   set_gidt   get_gidR   R   R   R   R   RJ   R   R>   R@   (	   RV   R)   t   argsRx   RC   R   RA   RB   R1   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR8   :  s(    		
c   	      C` s   t  |  j  r |  j |  |  S| j | j } } |  j   \ } } } } | | k rf | | } } n  | | k r | | } } n  | d k	 r | d k	 r | | k o | k n o | | k o | k n } n t } | i  f S(   uI   
        Test whether the mouse event occurred within the image.
        N(   t   callablet	   _containst   xdatat   ydatat
   get_extentR   R'   (	   RV   t
   mouseeventR/   R0   R   R   R   R   t   inside(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   containsX  s    ;c         C` sW   |  j  |  j d k r+ |  j d d d  n |  j d t d t } t j | |  d S(   u&   Write the image to png file with fnameu   lowerNiR   Rt   (   R   Rk   R|   Ri   t   _pngt	   write_png(   RV   t   fnameR   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR   p  s    4c         C` s  t  | d  rK | j d k r9 t | j d   |  _ qc t |  |  _ n t j | d t |  _ |  j j t	 j
 k r t	 j |  j j t d  r t d   n  |  j j d k p |  j j d k o |  j j d	 d k s t d   n  |  j j d k rt	 j |  j j t	 j  rd n d } |  j j   d k  sO| |  j j   k  rzt j d  t	 j |  j d |  |  _ n  |  j j t	 j
 k rt	 j |  j j t	 j  r|  j j t	 j
  |  _ qn  d |  _ d |  _ t |  _ d S(   u   
        Set the image array.

        ACCEPTS: numpy/PIL Image A

        Note that this function does *not* update the normalization used.
        u   getpixelu   Lu   RGBAt   copyu	   same_kindu'   Image data cannot be converted to floati   i   ii   u!   Invalid dimensions for image datai   i   i    um   Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).N(   i   i   (   t   hasattrt   modet   pil_to_arrayt   convertR|   t   cbookt   safe_masked_invalidRi   R   R   R   t   can_castt   floatt	   TypeErrorR   R   t
   issubdtypet   integerR   R   t   _logt   warningR   R   R   Rp   R   R   (   RV   RR   t   high(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   set_datav  s.    	('*$		c         C` s   |  j  |  d S(   uz   
        Retained for backwards compatibility - use set_data instead

        ACCEPTS: numpy array A or PIL Image
        N(   R   (   RV   RR   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt	   set_array  s    
c         C` s   |  j  S(   u*  
        Return the interpolation method the image uses when resizing.

        One of 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36',
        'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom',
        'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', or 'none'.

        (   t   _interpolation(   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    	c         C` sV   | d k r t d } n  | j   } | t k r@ t d   n  | |  _ t |  _ d S(   u<  
        Set the interpolation method the image uses when resizing.

        if None, use a value from rc setting. If 'none', the image is
        shown as is without interpolating. 'none' is only supported in
        agg, ps and pdf backends and will fall back to 'nearest' mode
        for other backends.

        .. ACCEPTS: ['nearest' | 'bilinear' | 'bicubic' | 'spline16' |
           'spline36' | 'hanning' | 'hamming' | 'hermite' | 'kaiser' |
           'quadric' | 'catrom' | 'gaussian' | 'bessel' | 'mitchell' |
           'sinc' | 'lanczos' | 'none' ]

        u   image.interpolationu   Illegal interpolation stringN(   R   R   t   lowerRU   R   R   Ri   R   (   RV   t   s(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRn     s    	c         C` s+   |  j    } |  j d k o* | j o* | j S(   uS   
        Returns `True` if the image can be composited with its neighbors.
        u   none(   R   R   R   t   is_separable(   RV   R1   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRK     s    	c         C` s/   | d k r t d } n  | |  _ t |  _ d S(   u[   
        Set whether or not image resampling is used.

        ACCEPTS: True|False
        u   image.resampleN(   R   R   t	   _resampleRi   R   (   RV   RY   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRo     s    	c         C` s   |  j  S(   u"   Return the image resample boolean.(   R   (   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    c         C` s(   | r d |  _  n	 d |  _  t |  _ d S(   uy   
        Set whether the resize filter norms the weights -- see
        help for imshow

        ACCEPTS: 0 or 1
        i   i    N(   t   _filternormRi   R   (   RV   Rv   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRl     s    	c         C` s   |  j  S(   u   Return the filternorm setting.(   R   (   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    c         C` s=   t  |  } | d k r' t d   n  | |  _ t |  _ d S(   u   
        Set the resize filter radius only applicable to some
        interpolation schemes -- see help for imshow

        ACCEPTS: positive float
        i    u+   The filter radius must be a positive numberN(   R   R   t
   _filterradRi   R   (   RV   Rw   t   r(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRm     s
    	c         C` s   |  j  S(   u   Return the filterrad setting.(   R   (   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    (%   t   __name__t
   __module__t   zordert   propertyR   t
   deprecatedRW   R\   R_   Rc   R   R'   Rf   Rz   R~   R   R   Ri   R   R   R   R   R	   R8   R   R   R   R   R   Rn   RK   Ro   R   Rl   R   Rm   R   (    (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR6      sN   !	 			
		 					/				
					t	   AxesImagec        	   B` sq   e  Z d    Z d d d d d d d e d  Z d d  Z d e d  Z d   Z d   Z	 d	   Z
 d
   Z RS(   c         C` s   d t  |  j j j  S(   Nu   AxesImage(%g,%g;%gx%g)(   R`   Ra   R2   Rb   (   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRc     s    i   g      @c
         K` sP   | |  _  t t |   j | d | d | d | d | d | d | d |	 |
 d S(	   u  
        interpolation and cmap default to their rc settings

        cmap is a colors.Colormap instance
        norm is a colors.Normalize instance to map luminance to 0-1

        extent is data axes (left, right, bottom, top) for making image plots
        registered with data plots.  Default is to label the pixel
        centers with the zero-based row and column indices.

        Additional kwargs are matplotlib.artist properties

        Rs   Rt   Ru   Rk   Rv   Rw   R   N(   t   _extentRy   R   Rf   (   RV   Rr   Rs   Rt   Ru   Rk   t   extentRv   Rw   R   Rx   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRf     s    	c         C` sC   |  j  \ } } } } t j | | | | g  } | j |  j j  S(   N(   R  R   t   from_extentst   transformedRa   t	   transData(   RV   R)   R#   t   x1R$   t   y1R2   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   get_window_extent<  s    g      ?c         C` s   |  j    } |  j   \ } } } } t t j | | g | | g g   }	 t |	 |  }
 |  j |  j |	 |
 |  j j	 | d | S(   NR   (
   R   R   R   R   R   R   R   R|   Ra   R2   (   RV   R)   R*   R   R1   R  t   x2R  t   y2R2   t   transformed_bbox(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR   A  s    'c         C` s   |  j    d k o | j   S(   uK   
        Return whether the image would be better drawn unsampled.
        u   none(   R   t   option_scale_image(   RV   R)   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR   L  s    c         C` s   | |  _  \ } } } } | | f | | f f } |  j j |  | | g |  j j (| | g |  j j (|  j j r |  j j | | f d d n  |  j j	 r |  j j
 | | f d d n  t |  _ d S(   ub  
        extent is data axes (left, right, bottom, top) for making image plots

        This updates ax.dataLim, and, if autoscaling, sets viewLim
        to tightly fit the image, regardless of dataLim.  Autoscaling
        state is not changed, so following this with ax.autoscale_view
        will redo the autoscaling in accord with dataLim.
        t   autoN(   R  Ra   t   update_datalimt   sticky_edgesR/   R0   t   _autoscaleXont   set_xlimR   t   _autoscaleYont   set_ylimRi   R   (   RV   R  R   R   R   R   t   corners(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt
   set_extentS  s    	c         C` sq   |  j  d k	 r |  j  S|  j   } | \ } } |  j d k rU d | d | d d f Sd | d d | d f Sd S(   u.   Get the image extent: left, right, bottom, topu   upperg      g      ?N(   R  R   R~   Rk   (   RV   t   szt   numrowst   numcols(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR   g  s    c         C` sI  |  j    \ } } } } |  j d k r7 | | } } n  |  j   } t | | g | | g g  } t d d g | j d  g  } t d | d |  }	 | j | j }
 } |	 j |
 | g  } t	 t
 j |   r d S| j t  \ } } d | k o	| j d k  n s3d | k o-| j d k  n r7d S| | | f Sd S(   u%   Get the cursor data for a given eventu   upperi    i   t   boxint   boxouti   N(   R   Rk   R   R   R   R   R   R   t   transform_pointRH   R   R   R   R   R   (   RV   t   eventR   R   R   R   t   arrt   data_extentt   array_extentR1   R0   R/   t   pointt   it   j(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   get_cursor_datas  s    HN(   R   R   Rc   R   R'   Rf   R  R   R   R  R   R#  (    (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s   	 			t   NonUniformImagec           B` sq   e  Z d    Z d   Z d e d  Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z RS(   c         K` s<   | j  d d  } t t |   j | |  |  j |  d S(   u   
        kwargs are identical to those for AxesImage, except
        that 'nearest' and 'bilinear' are the only supported 'interpolation'
        options.
        u   interpolationu   nearestN(   t   popRy   R$  Rf   Rn   (   RV   Rr   Rx   t   interp(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRf     s    c         C` s   t  S(   u;   
        return False. Do not use unsampled image.
        (   R'   (   RV   R)   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    g      ?c         C` s  |  j  d  k r t d   n  | r3 t d   n  |  j  } | j d k r | j t j k r |  j | d t	 } |  j
 j   |  _ qt j | d  d   d  d   t j f d d  } d | d  d   d  d   d f <t	 |  _ n | j t j k rd | j t j  } n  | j d d k rt j t t | j d d ! d g  t j  } | | d  d   d  d   d d  f <d | d  d   d  d   d f <| } n  t |  _ |  j j j \ } } } }	 |  j j j \ }
 } } } t j |  d	 t j |
  d	 } t j |  d	 t j |  d	 } | | 9} | | 9} t j |  j |  j | t |  t |  | | | | | |	 f t  |  j!  } | |
 | t"   f S(
   Nu"   You must first set the image arrayu*   unsampled not supported on NonUniformImagei   R   i   i   i   i    g      ?(#   R|   R   R}   R   R   R   R   R   R   Ri   Rs   t   is_grayt   is_grayscalet   repeatt   newaxisR   R   R   R`   t   listR'   Ra   t   viewLimRb   R2   t   extentsR?   R%   t   pcolort   _Axt   _AyR   RU   R   R   (   RV   R)   R*   R   RR   t   BR#   R$   t   v_widtht   v_heightRA   RB   R   R   R!   R    R   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s>    	12%		$$

c         C` sH  t  j | t  j  } t  j | t  j  } t j | d t } | j | j k o\ d k n o~ | j d d !| j | j k s t d   n  | j d k r t d   n  | j d k r | j d d k r t d	   n  | j d k r| j d d k r| j d d !| _ n  | |  _	 | |  _
 | |  _ d
 |  _ t |  _ d
 S(   u^  
        Set the grid for the pixel centers, and the pixel values.

          *x* and *y* are monotonic 1-D ndarrays of lengths N and M,
             respectively, specifying pixel centers

          *A* is an (M,N) ndarray or masked array of values to be
            colormapped, or a (M,N,3) RGB array, or a (M,N,4) RGBA
            array.
        R   i   i    i   u   Axes don't match array shapei   u   Can only plot 2D or 3D datai   u?   3D arrays must have three (RGB) or four (RGBA) color componentsN(   i   i   (   i   i   i   (   R   R   R   R   R   Ri   R   R   R   R|   R/  R0  R   Rp   R   (   RV   R/   R0   RR   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s     B""				c         G` s   t  d   d  S(   Nu   Method not supported(   t   NotImplementedError(   RV   R   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    c         C` s;   | d k	 r' | d k r' t d   n  t j |  |  d S(   u|   
        Parameters
        ----------
        s : str, None
            Either 'nearest', 'bilinear', or ``None``.
        u   nearestu   bilinearu?   Only nearest neighbor and bilinear interpolations are supportedN(   u   nearestu   bilinear(   R   R4  R   Rn   (   RV   R   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRn     s    c         C` sJ   |  j  d  k r t d   n  |  j d |  j d |  j d |  j d f S(   Nu   Must set data firsti    i(   R|   R   R}   R/  R0  (   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    c         C` s   d  S(   N(    (   RV   R   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRl     s    c         C` s   d  S(   N(    (   RV   R   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRm     s    c         C` s8   |  j  d  k	 r t d   n  t t |   j |  d  S(   Nu'   Cannot change colors after loading data(   R|   R   R}   Ry   R$  t   set_norm(   RV   Rt   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR5    s    c         C` s8   |  j  d  k	 r t d   n  t t |   j |  d  S(   Nu'   Cannot change colors after loading data(   R|   R   R}   Ry   R$  t   set_cmap(   RV   Rs   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR6    s    (   R   R   Rf   R   R'   R   R   R   Rn   R   Rl   Rm   R5  R6  (    (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR$    s   	
	'							t   PcolorImagec           B` sY   e  Z d  Z d d d d d d  Z d e d  Z d   Z d   Z d   Z	 d   Z
 RS(	   u   
    Make a pcolor-style plot with an irregular rectangular grid.

    This uses a variation of the original irregular image code,
    and it is used by pcolorfast for the corresponding grid type.
    c         K` sU   t  t |   j | d | d | |  j |  | d k	 rQ |  j | | |  n  d S(   u   
        cmap defaults to its rc setting

        cmap is a colors.Colormap instance
        norm is a colors.Normalize instance to map luminance to 0-1

        Additional kwargs are matplotlib.artist properties
        Rt   Rs   N(   Ry   R7  Rf   Rq   R   R   (   RV   Rr   R/   R0   RR   Rs   Rt   Rx   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRf   
  s    "g      ?c      
   C` s  |  j  d  k r t d   n  | r3 t d   n  |  j j j   } t j | d  } t	 j
 |  d j t	 j  } |  j j j \ } } } }	 t	 j |  d t	 j |  d }
 t	 j |	  d t	 j |  d } t t	 j |
 |   }
 t t	 j | |   } |  j d  k re|  j |  j  d t } | |  _ |  j  j d k rn|  j j   |  _ qnn	 |  j } |  j j } t j |  j |  j | | |
 | j | j | j | j f |  } | | | t    f S(   Nu"   You must first set the image arrayu&   unsampled not supported on PColorImagei    i   g      ?R   i   (!   R|   R   R}   R   Ra   t   patcht   get_facecolorR   R   R   R   R   R   R2   R-  R?   R   R   Ri   R   Rs   R'  R(  R,  R%   t   pcolor2R/  R0  R#   R  R$   R  R   (   RV   R)   R*   R   t   fct   bgRA   RB   R   R   R!   R    RR   t   vlR   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s2    $$			c         C` s   t  S(   N(   R'   (   RV   R)   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR   <  s    c         C` s  t  j | d t } | d
 k rJ t j d | j d d d t j } n t j | t j  j	   } | d
 k r t j d | j d d d t j } n t j | t j  j	   } | j d  | j
 d | j
 d f k rt d | j d  | j
 d | j
 d f f   n  | j d k r.t d   n  | j d k rc| j d d k rc| j d  | _ n  t |  _ | j d k r4| j d d k r%| d
 d
  d
 d
  d f | d
 d
  d
 d
  d f k j   r1| d
 d
  d
 d
  d f | d
 d
  d
 d
  d f k j   r1t |  _ q1q4t d   n  | d | d k  r}| d
 d
 d  } | d
 d
  d
 d
 d  f } n  | d | d k  r| d
 d
 d  } | d
 d
 d  } n  | |  _ | |  _ | |  _ d
 |  _ t |  _ d
 S(   u  
        Set the grid for the rectangle boundaries, and the data values.

          *x* and *y* are monotonic 1-D ndarrays of lengths N+1 and M+1,
             respectively, specifying rectangle boundaries.  If None,
             they will be created as uniform arrays from 0 through N
             and 0 through M, respectively.

          *A* is an (M,N) ndarray or masked array of values to be
            colormapped, or a (M,N,3) RGB array, or a (M,N,4) RGBA
            array.

        R   i    i   R   i   u2   Axes don't match array shape. Got %s, expected %s.i   u   A must be 2D or 3Di   Nu+   3D arrays must have RGB or RGBA as last dimi(   i   i   (   i   i   (   R   R   Ri   R   R   t   arangeR   R   R   t   ravelR9   R   R   R'   R(  t   allR|   R/  R0  R   R   (   RV   R/   R0   RR   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR   ?  sB    ))'."	DD"				c         G` s   t  d   d  S(   Nu   Method not supported(   R4  (   RV   R   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR   v  s    c         C` s   | j  | j } } | |  j d k  s_ | |  j d k s_ | |  j d k  s_ | |  j d k rc d St j |  j |  d } t j |  j |  d } y |  j | | f SWn t k
 r d SXd S(   u%   Get the cursor data for a given eventi    ii   N(	   R   R   R/  R0  R   R   t   searchsortedR|   t
   IndexError(   RV   R  R/   R0   R"  R!  (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR#  y  s    &&N(   R   R   t   __doc__R   Rf   R'   R   R   R   R   R#  (    (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR7    s   		7	t   FigureImagec           B` sM   e  Z d  Z d Z d d d  d  d d  Z d   Z d e d  Z d   Z	 RS(   i    u   nearestc         K` s]   t  t |   j d d | d | d | | |  _ | |  _ | |  _ |  j |  d |  _ d S(   u   
        cmap is a colors.Colormap instance
        norm is a colors.Normalize instance to map luminance to 0-1

        kwargs are an optional list of Artist keyword args
        Rt   Rs   Rk   g      ?N(	   Ry   RD  Rf   R   t   figuret   oxt   oyRq   R*   (   RV   t   figRs   Rt   t   offsetxt   offsetyRk   Rx   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRf     s    			c         C` sF   |  j    \ } } d |  j | d |  j d |  j | d |  j f S(   u.   Get the image extent: left, right, bottom, topg      g      ?(   R~   RF  RG  (   RV   R  R  (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    g      ?c   	      C` s   | j  |  j j  } t |  j | |  j | g |  j | |  j j d |  j | |  j j d g g  } |  j j   \ } } | | j  9} | | j  9} t d d g | | g g  } |  j |  j | | | d | | d | d t	 S(   Ni   i    R*   R   R   (
   t   dpiRE  R   RF  RG  R|   R   t   get_size_inchesR   R'   (	   RV   R)   R*   R   t   facR2   R!   R    R   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    $c         C` s/   t  j j |  t j | d t  t |  _ d S(   u   Set the image array.R   N(   Rg   Rh   R   R   R   Ri   R   (   RV   RR   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    N(
   R   R   R   R   R   Rf   R   R'   R   R   (    (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRD    s   	t	   BboxImagec        	   B` s\   e  Z d  Z d	 d	 d	 d	 d d e e d  Z d   Z d	 d  Z d   Z	 d e d  Z
 RS(
   u;   The Image class whose size is determined by the given bbox.i   g      @c
         K` se   t  t |   j d d | d | d | d | d | d | d | |
 | |  _ |	 |  _ t   |  _ d S(	   uG  
        cmap is a colors.Colormap instance
        norm is a colors.Normalize instance to map luminance to 0-1

        interp_at_native is a flag that determines whether or not
        interpolation should still be applied when the image is
        displayed at its native resolution.  A common use case for this
        is when displaying an image for annotational purposes; it is
        treated similarly to Photoshop (interpolation is only used when
        displaying the image at non-native resolutions).


        kwargs are an optional list of Artist keyword args

        Rs   Rt   Ru   Rk   Rv   Rw   R   N(   Ry   RN  Rf   R   R2   t   interp_at_nativeR   t
   _transform(   RV   R2   Rs   Rt   Ru   Rk   Rv   Rw   R   RO  Rx   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRf     s    		c         C` s   |  j  S(   N(   RP  (   RV   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    c         C` sc   | d  k r |  j   j } n  t |  j t  r7 |  j St |  j  rS |  j |  St d   d  S(   Nu   unknown type of bbox(   R   t
   get_figuret   _cachedRendererR5   R2   R   R   R   (   RV   R)   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR    s    c         C` sj   t  |  j  r |  j |  |  S|  j   s5 t i  f S| j | j } } |  j   j | |  } | i  f S(   u7   Test whether the mouse event occurred within the image.(   R   R   R   R'   R/   R0   R  R   (   RV   R   R/   R0   R   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    
g      ?c   	      C` s   | j    \ } } |  j |  j   } | j | | g _ |  j |  } t d d g | | g g  } t t d d g d d g g  |  |  _ |  j |  j | | | | d | S(   Ni    i   R   (	   t   get_canvas_width_heightR  R   t   _pointsR   R   RP  R   R|   (	   RV   R)   R*   R   R!   R    t   bbox_int   bbox_outR   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    *N(   R   R   RC  R   R'   Ri   Rf   R   R  R   R   (    (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyRN    s   "		c   
      C` s  d   } i t  j d 6} | d k r t |  t j  r t |   } t | j  d k ra d } q t	 j
 j |   \ } } | j   d } q t |  d  r t	 j
 j |  j  \ } } | j   d } q d } n | } | | k r| |   } | d k rt d t |    n  | S| | } t |  t j  rt |   } t | j  d k rxt t |   j    }	 | |	  St |  d   }	 | |	  SWd QXn
 | |   Sd S(   u  
    Read an image from a file into an array.

    *fname* may be a string path, a valid URL, or a Python
    file-like object.  If using a file object, it must be opened in binary
    mode.

    If *format* is provided, will try to read file of that type,
    otherwise the format is deduced from the filename.  If nothing can
    be deduced, PNG is tried.

    Return value is a :class:`numpy.array`.  For grayscale images, the
    return array is MxN.  For RGB images, the return value is MxNx3.
    For RGBA images the return value is MxNx4.

    matplotlib can only read PNGs natively, but if `PIL
    <http://www.pythonware.com/products/pil/>`_ is installed, it will
    use it to load the image and return an array (if possible) which
    can be used with :func:`~matplotlib.pyplot.imshow`. Note, URL strings
    may not be compatible with PIL. Check the PIL documentation for more
    information.
    c         S` sO   y d d l  m } Wn t k
 r( d SX| j |    } t |  SWd QXd S(   u-   try to load the image with PIL or return Nonei    (   t   ImageN(   t   PILRW  t   ImportErrorR   t   openR   (   R   RW  R-   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   pilread1  s    u   pngi   u   nameu_   Only know how to handle extensions: %s; with Pillow installed matplotlib can handle more imagesu   rbN(   R   t   read_pngR   R5   RZ   t   string_typesR   R   t   schemet   ost   patht   splitextR   R   t   nameR   R+  R   R   t   readRZ  (
   R   R   R[  t   handlerst   parsedt   extt   basenameR   t   handlert   fd(    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   imread  s:    				

id   c         C` s>  d d l  m } d d l m }	 t |  t t d d   rM t j |   }  n  | d k s | d k r t |  t	 j
  r |  j   j d  r t d d | d | }
 |
 j |  |
 j | |  |
 j |   ni |	 d	 | d
 t  } | |  | j | d | d | d | d | d t | j |  d	 | d | d t d S(   uF  
    Save an array as in image file.

    The output formats available depend on the backend being used.

    Parameters
    ----------
    fname : str or file-like
        Path string to a filename, or a Python file-like object.
        If *format* is *None* and *fname* is a string, the output
        format is deduced from the extension of the filename.
    arr : array-like
        An MxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA) array.
    vmin, vmax: [ None | scalar ]
        *vmin* and *vmax* set the color scaling for the image by fixing the
        values that map to the colormap color limits. If either *vmin*
        or *vmax* is None, that limit is determined from the *arr*
        min/max value.
    cmap : matplotlib.colors.Colormap, optional
        For example, ``cm.viridis``.  If ``None``, defaults to the
        ``image.cmap`` rcParam.
    format : str
        One of the file extensions supported by the active backend.  Most
        backends support png, pdf, ps, eps and svg.
    origin : [ 'upper' | 'lower' ]
        Indicates whether the ``(0, 0)`` index of the array is in the
        upper left or lower left corner of the axes.  Defaults to the
        ``image.origin`` rcParam.
    dpi : int
        The DPI to store in the metadata of the file.  This does not affect the
        resolution of the output image.
    i    (   t   FigureCanvasAgg(   t   Figureu   PathLikeu   pngu   .pngRs   Rk   RK  t   frameonR   R   t   resizeR   t   transparentN(    (   t   matplotlib.backends.backend_aggRk  t   matplotlib.figureRl  R5   t   getattrR_  t   fspathR   RZ   R]  R   t   endswithR   R   t   set_climR   R'   t   figimageRi   t   savefig(   R   R  R   R   Rs   R   Rk   RK  t   FigureCanvasRl  R-   RH  (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   imsavef  s"    "
$c         C` s   |  j  d k r t j |   S|  j  j d  r |  j d |  j   } |  j  j d  rj t j | d  } n t j | d	  } | j |  j d
 d
 d   j	 d  Sy |  j
 d  }  Wn t k
 r t d   n Xt j |   Sd
 S(   u   Load a PIL image and return it as a numpy array.

    Grayscale images are returned as ``(M, N)`` arrays.  RGB images are
    returned as ``(M, N, 3)`` arrays.  RGBA images are returned as ``(M, N,
    4)`` arrays.
    u   RGBAu   RGBXu   RGBu   Lu   I;16u   rawu   Bu   >u2u   <u2Niu   =u2u   Unknown image mode(   u   RGBAu   RGBXu   RGBu   L(   R   R   R   t
   startswitht   tobytesRt  t
   fromstringt   reshapeR9   R   R   R   R}   (   t   pilImaget   rawR/   (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyR     s    &g?c      
   C` s  t  j j |   \ } } t  j j |  \ } } t |   }	 |	 j \ }
 } } d } |
 | | } | | | } | j   } | r d d l j } | j	 d | | f d |  } n | d k r d d l
 m } nJ | d k r d d	 l m } n+ | d
 k rd d l m } n t d   d d l m } | d | | f d |  } | |  | j d d d d g d d d t d g  d g  } t  j j |  \ } } | j |	 d d d t d | | j | d | | S(   u  
    make a thumbnail of image in *infile* with output filename
    *thumbfile*.

      *infile* the image file -- must be PNG or Pillow-readable if you
         have `Pillow <http://python-pillow.org/>`_ installed

      *thumbfile*
        the thumbnail filename

      *scale*
        the scale factor for the thumbnail

      *interpolation*
        the interpolation scheme used in the resampling


      *preview*
        if True, the default backend (presumably a user interface
        backend) will be used which will cause a figure to be raised
        if :func:`~matplotlib.pyplot.show` is called.  If it is False,
        a pure image backend will be used depending on the extension,
        'png'->FigureCanvasAgg, 'pdf'->FigureCanvasPdf,
        'svg'->FigureCanvasSVG


    See examples/misc/image_thumbnail.py.

    .. htmlonly::

        :ref:`sphx_glr_gallery_misc_image_thumbnail_sgskip.py`

    Return value is the figure instance containing the thumbnail

    id   i    Nt   figsizeRK  u   .png(   Rk  u   .pdf(   t   FigureCanvasPdfu   .svg(   t   FigureCanvasSVGu0   Can only handle extensions 'png', 'svg' or 'pdf'(   Rl  i   t   aspectu   autoRm  t   xtickst   yticksR   Ru   (   R_  R`  t   splitRa  Rj  R   R   t   matplotlib.pyplott   pyplotRE  Rp  Rk  t   matplotlib.backends.backend_pdfR  t   matplotlib.backends.backend_svgR  R   Rq  Rl  t   add_axesR'   t   imshowRi   Rw  (   t   infilet	   thumbfileR   Ru   t   previewt   basedirRg  t   baseoutt   extoutR   t   rowst   colst   depthRK  R    R!   t	   extensiont   pltRH  Rx  Rl  Rr   Rf  (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt	   thumbnail  s6    %!
(S   RC  t
   __future__R    R   R   R   RZ   t   six.moves.urllib.parseR   t   six.moves.urllib.requestR   t   ioR   t   mathR   R_  t   loggingt   numpyR   t
   matplotlibR   t   matplotlib.artistt   artistRd   R	   t   matplotlib.colorst   colorsR   t   matplotlib.cmRg   t   matplotlib.cbookR   t   matplotlib._imageR%   t   matplotlib._pngR   t   matplotlib.transformsR   R   R   R   R   R   t	   getLoggerR   R   R&   t   BILINEARt   BICUBICt   SPLINE16t   SPLINE36t   HANNINGt   HAMMINGt   HERMITEt   KAISERt   QUADRICt   CATROMt   GAUSSIANt   BESSELt   MITCHELLt   SINCt   LANCZOSt   BLACKMANRU   t   setR^   R4   R   RQ   RT   Re   Rh   R6   R   R$  R7  RD  RN  Rj  Ry  R   R'   R  (    (    (    s/   lib/python2.7/site-packages/matplotlib/image.pyt   <module>   sr   "
.
















;-	  [x{=UM5	