rL idZddlZddlZddlZddlmZddlZddlZddl Z ddl Z ddl Z ddl mZmZddl mZddlddlmZddlmZddlmZddlmZddlmZmZm Z m!Z!m"Z"m#Z#m$Z$ejJe&Z'id ejPd ejPd ejPd ejRd ejTdejVdejXdejZdej\dej^dej`dejbdejddejfdejhdejjdejlejnejpejPdZ9e:e9Z;d3dZ< d4dZ=ddddZ>d Z?Gd!d"ejZAGd#d$eAZBGd%d&eBZCGd'd(eBZDGd)d*eAZEGd+d,eAZFd4d-ZG d5ddd.d/ZHd0ZId1ZJ d6d2ZKy)7zR The image module supports basic image loading, rescaling and display operations. N)Path)_apicbook)_image)*)FigureCanvasBase)Affine2DBboxBaseBbox BboxTransformBboxTransformToIdentityTransformTransformedBboxautononenearestbilinearbicubicspline16spline36hanninghamminghermitekaiserquadriccatromgaussianbesselmitchellsinc)lanczosblackman antialiasedc t|dk(r(tjdtjddfSg}g}|D]}|j ||\}}}} |||z}||z}|j ||||j f|j t||g||jdz||jdzggt|dk(r(tjdtjddfStj|} tjt| jt| jdftj} |D]d\}}}} tj|| j z || j"z } t%j&|| | t$j(d| f| | j |z | j"|z fS)a5 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` magnification : float, default: 1 The additional magnification to apply for the renderer in use. Returns ------- image : (M, N, 4) `numpy.uint8` array The composited RGBA image. offset_x, offset_y : float The (left, bottom) offset where the composited image should be placed in the output figure. r)rrdtyper%Fresamplealpha)lennpemptyuint8 make_imageappend_get_scalar_alphar shapeunionzerosintheightwidthr translatex0y0rr*NEAREST) imagesrenderer magnificationpartsbboxesimagedataxytransbboxoutputr+s V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/image.pycomposite_imagesrJ<s4 6{axx 2Aq88 E FH!,,X}EaE    A  A LL$1e&=&=&?@ A MMq!fq4::a=0!djjm2CDEF H H 5zQxx 2Aq88 ::f D XX T[[ 3tzz?A.bhh@F#5aE $$Q[!dgg+>feV^^!&e 55 477]*DGGm,C CCc td|D}||nj}|s|s|D]}|jygj  fd}|D]l}t |t rB|j r2|jr"|jsj|U||jn|y)a 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. c3<K|]}t|tywN) isinstance _ImageBase.0rDs rI z0_draw_list_compositing_images..~s@1Z:.@sNctdk(rdjntdkDrt\}}}|jdk7rj }|j j |jjj|t|t|||jdd=y)Nr(r) r,drawrJsizenew_gcset_clip_rectanglerG set_clip_path get_clip_path draw_imageroundrestore)rClbgc image_groupmagparentr>s rI flush_imagesz3_draw_list_compositing_images..flush_imagess;1$A##H-[!A%-k8SI a99>!*B))&++6$$V%9%9%;<''E!HeAhEJJLArK) anyoption_image_nocompositerUget_image_magnificationrOrP can_composite get_clip_onrZr1) r>rcartistssuppress_composite has_images not_compositeardrarbs `` @@rI_draw_list_compositing_imagesrots@@@J,>+I'";;=J A FF8   ..0  !A1j)aoo.?MMOAOO,=""1%x  ! rKr(r)c d}|jddkDr|tj|jdt t j |jddz }|dddd|f}tj|d|z}|jddkDr|tj|jd t t j |jddz }|dd|ddf}tjd||z}|j}|d vr!t jddg|jd|jdgg} |j| } t jt j| dddf} t jt j| dddf} | d |jdzkDs'| |jdk(s| d |jdzk(r?| d |jdzkDs'| |jdk(s| d |jdzk(rd }nd}t j||jd dz|j} ||j!}t#j$|| |t&||||j)|j+| S)a Convenience wrapper around `._image.resample` to resample *data* to *out_shape* (with a third dimension if *data* is RGBA) that takes care of allocating the output array and fetching the relevant properties from the Image object *image_obj*. zData with more than {n} cannot be accurately displayed. Downsampling to less than {n} before displaying. To remove this warning, manually downsample your data.r(iz 2**23 columns)nNriz 2**24 rowsr#rrr)r3warningswarnformatr6r-ceilr scaleget_interpolationarray transformabsdiffr5r' get_resamplerr* _interpd_get_filternorm get_filterrad) image_objrC out_shaper|r*r+msgstep interpolationposdispdispxdispyouts rI _resamplersw DC zz!}u cjj?j342774::a=5012AvvIJ$$T1- 9  zz!}u cjj?@""3'rwwtAqDz*+rwwtAqDz*+ QA& &A&TZZ]** QA& &A&TZZ]**%M%M ((9tzz!"~-tzz :C))+ OOD#ym,,,.++- / JrKc tj|jd|jddf|j}||ddddddf<|jtjk(rd|dddddf<|Sd|dddddf<|S) z\ Convert an RGB image to RGBA, as required by the image resample C++ extension. rr(r%r&Nrs?)r-r5r3r'r/)Argbas rI _rgb_to_rgbars~ 88QWWQZQ/qww ?DDArrN zzRXXQ1W  KQ1W KrKceZdZdZdZ d!ddfd ZdZfdZdZd Z d Z d Z fd Z d"d Z d#dZdZej"dZdZdZedZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"d Z#xZ$S)$rPa Base class for images. 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 rN)interpolation_stagec  t ||j||||tjd}t j ddg|||_|j||j||j||j| |j| ||_ d|_|j| y)N image.originupperlowerorigin)super__init___get_colorizermplrcParamsr check_in_listrset_filternorm set_filterradset_interpolationset_interpolation_stage set_resampleaxes_imcache_internal_update) selfaxcmapnorm colorizerrr filternorm filterradr*rkwargs __class__s rIrz_ImageBase.__init__s ,,T4CD >\\.1F GW-f=  J' 9% }- $$%89 (#   f%rKc |j}t|jd|dS#t$rt|jcYSwxYw)Nz(shape=)) get_shapetype__name__ RuntimeError)rr3s rI__str__z_ImageBase.__str__sP 'NN$E4j))*'%!< < ':&& & 's*-A Ac,it|ddiS)Nr)r __getstate__rrs rIrz_ImageBase.__getstate__s;%'&(;*d;;rKc(|jddS)z9Return the size of the image as tuple (numrows, numcols).Nrt)rrs rIget_sizez_ImageBase.get_size"s~~##rKc\|j td|jjS)zV Return the shape of the image as tuple (numrows, numcols, channels). "You must first set the image array)_Arr3rs rIrz_ImageBase.get_shape&s' 77?CD Dww}}rKctjj||tj|dvr t dd|_y)z Set the alpha value used for blending - not supported on all backends. Parameters ---------- alpha : float or 2D array-like or None )rrtz5alpha must be a float, two-dimensional array, or NoneN)martistArtist_set_alpha_for_arrayr-ndim TypeErrorr)rr+s rI set_alphaz_ImageBase.set_alpha/sA ++D%8 775> '-. . rKcz|j"tj|jdkDrdS|jS)a Get a scalar alpha value to be applied to the artist as a whole. If the alpha value is a matrix, the method returns 1.0 because pixels have individual alpha values (see `~._ImageBase._make_image` for details). If the alpha value is a scalar, the method returns said value to be applied to the artist as a whole because pixels do not have individual alpha values. rr)_alphar-rrs rIr2z_ImageBase._get_scalar_alpha=s5kk)RWWT[[-AA-Es  rKc0d|_t| y)zU Call this whenever the mappable is changed so observers can update. N)rrchangedrs rIrz_ImageBase.changedJs  rKc $| td|jdk(r tdtj||}|y|j|z} |j |z} | dk(s| dk(ry|j dk(r9tjd|jd jdd} n t} | tj|j|jdz |j |jdz j|j|j|jzz } | tj|j |j j|z} |s|| jrp|rn| d zd k7s| d zd k7r^t!j"| } t!j"| }| | z | z }|| z | z }| tjd |zd |zz } nt%| } t%| }|| f}|s}|j&d k(s9|j&d k(r|jdd vst)d|jd|j*}|dvrt-j.ddg|jd|jdgg}| j1|}t-j2t-j4|dddf|jdz }t-j2t-j4|dddf|jdz }|d ks|d krd}nd}|j&d k(rt|dk(rn|j6j8dk(rzt-j6|j6j:dkDrdnd}|j:|j6j:krot=j>d|j6d|dnH|jAjCd|jEjCdz }|dkDrdnd}tG||jC||| }tI|jJtLjNr|jC|j6}|jPj|jk(rUt-jR|jPt-jTt,jVt-jTdn#t-jX|t,jT}tG|||| d}~t-jZ|}d||<|j]}|+t-j&|dkDr|tG|||| dz}t,j^ja||}|jK|}nd|j&d k(r,|jJjc||je|}|j]}|d|jd d k(r"|j6t,jfk(rdnd } ntG||d|| } tG|ti|ddd f|| }nt-j&|dkDr-tG|||| } tG|ti|ddd f|| }ni|jd d k(r%|j6t,jfk(rd|zn|} ntG||d|| |z} tG|ti|ddd f|| }| |d<|je|dd !}|j&d k(r|jk}|ddddd f}!|!jCt,jTz|z|!ddn\|jl&|je|d|j&d k(!|_6|jl}to|| jqjs}"|t%tA|"jtdt%tE|"jvdz|jdt%tA|"jxdt%tE|"jzdz|jdf}tjt%tA|"jxdt%tA|"jtd| z} ||j|j| fS)"a Normalize, rescale, and colormap 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. Parameters ---------- A : ndarray - a (M, N) array interpreted as scalar (greyscale) image, with one of the dtypes `~numpy.float32`, `~numpy.float64`, `~numpy.float128`, `~numpy.uint16` or `~numpy.uint8`. - (M, N, 4) RGBA image with a dtype of `~numpy.float32`, `~numpy.float64`, `~numpy.float128`, or `~numpy.uint8`. in_bbox : `~matplotlib.transforms.Bbox` out_bbox : `~matplotlib.transforms.Bbox` clip_bbox : `~matplotlib.transforms.Bbox` magnification : float, default: 1 unsampled : bool, default: False If True, the image will not be scaled, but an appropriate affine transformation will be returned instead. round_to_pixel_border : bool, default: True If 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 if exact scaling is needed, such as for `.FigureImage`. Returns ------- image : (M, N, 4) `numpy.uint8` array The RGBA image, resampled unless *unsampled* is True. x, y : float The upper left corner where the image should be drawn, in pixel space. trans : `~matplotlib.transforms.Affine2D` The affine transformation from image to pixel space. Nz9You must first set the image array or the image attributerzk_make_image must get a non-empty image. Your Artist's draw method must filter before this method is called.)NrrNrr(rrtrsrsr%Invalid shape  for image datarrrrCfr%f8f4zCasting input data from z to z for imshow.gחAT)r*r).rs.Fbytesr)>rrVr intersectionr8r7rr r9r3ryrr:r; get_transform is_affinemathrxr6r ValueError_interpolation_stager-r{r|r}r~r'kinditemsizer warn_externalmaxastypeminrrOrmcolorsNoNormmaskwherefloat32nan ones_likeisnan get_alphama masked_arrayautoscale_Noneto_rgbar/rr2rrinvertedfrozenyminymaxxminxmax)#rrin_bboxout_bbox clip_bboxr? unsampledround_to_pixel_border clipped_bboxout_width_baseout_height_baset0t out_width out_height extra_width extra_heightrrrrrr scaled_dtypeda A_resampledr out_alphaout_maskr+resampled_maskedrH output_alpha alpha_channelsubsets# rI _make_imagez_ImageBase._make_imageQs\ 9 >? ? 66Q; 89 9((9=  #%++m;&-- = Q /Q"6# ;;' !%%a!''!*5;;ArBB"$B J U  *+-Ywzz7:: .  "  # $ LOO+loo-=>}%' 0E#%,#0E0L .1I?3J$~5GK&8OKL !!# "3S<5GH HAN+I_-J+ FFaK166Q;1772;&3H >!''/!JKK#'";"; "&==hhAQWWQZ(@AB{{3'rwwtAqDz23aggaj@rwwtAqDz23aggaj@AI519*0'*0'vv{2f< 77<<3&#%88AGG4D4Dq4HDd#SL#,,qww/?/??**-EaggY-1,|,MN -t0DDB+-84L(ahh|.DiQRS dii8"-"4"4QWW"=K66<<1772BFF);RZZ]K\\!RZZ8 &dD)QN 88I.&' (#($!);4 1t!TTI#%55#5#5k8#L #3466Q;II,,Q/ QA(=wwqzQ./gg.Ass '0 !F)Y(; &l1S"1"W:6 1FFWWU^a'#,T5)Q#GL&l1S"1"W:6 1FFwwqzQ892888Ke QV '0qy)Q'ORW'W &l1S"1"W:6 1FF!-v\\&5\AFvv{..0 &q!Qw !((4y@5Ha }}$ $ Qd!&&A+ O ]]F%Y >EEGFC Q'(C aa9:;C Q'(C aa9:;;r?rs rIr0z_ImageBase.make_image-s$""LMMrKcy)z| Return whether the image is better to be drawn unsampled. The derived class needs to override it. Frs rI_check_unsampled_imagez!_ImageBase._check_unsampled_imageAs rKc`|jsd|_y|jjdk(rd|_y|j }|j ||j |j|j|j|j|j|jr|jr|jjrg|j!|d\}}}}|t#j%|j&d|j&d|z}|j)|||||n;|j!||j+\}}}}||j)|||||j-d|_y)NFrTrr() get_visiblestale get_arrayrVrW _set_gc_cliprr2set_urlget_urlset_gidget_gidoption_scale_imagerrrr0r ryr3r[rgr])rr>r`imr^r_rFs rIrUz_ImageBase.drawIsa!DJ  >>  A %DJ  __  " T++-. 4<<>" 4<<>"  ' ' )//1&&(22"ooh$oGOB1e~ ((!bhhqkBUJ##B1b%8"oo(::<>OB1e~##B1b1  rKc~|j|s|jj|dsdifS|jj }|j |j |jg\}}|j\}}}}|duxr$||z ||z zdkxr|duxr||z ||z zdk} | ifS)7Test whether the mouse event occurred within the image.rFN) _different_canvasrcontainsrrr|rDrE get_extent) r mouseeventrFrDrErrrrinsides rIr%z_ImageBase.containshs  " ": .yy))*5a8"9  ""$--/ jll;<1!%!2dD$4-EQX!d($;q$@EtmE)*Ta$h(?1(D rzrKc|j|jdk(r|jdddn |jdd}tjj |j |dy)z$Write the image to png file *fname*.rNrTrpng)rw)rrrPILImage fromarraysave)rfnamer!s rI write_pngz_ImageBase.write_pngzs[ \\4;;'+A$''$B$-tww $41 B$$U5$9rKctj|d}|jtjk7r>tj |jt dstd|jd|jdk(r#|jddk(r|jd}|jd k(s9|jdk(r|jdd vstd |jd |jdk(r tj|jtjrd nd}|jdks||jkrJtj!d|j|jtj"|d|}|jtjk7rMtj|jtjr|j%tj}|S)z| Check validity of image-like input *A* and normalize it to a format suitable for Image subclasses. T)copy same_kindzImage data of dtype z cannot be converted to floatrsrr(rtrrrrrzClipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Got range [%s..%s].)rsafe_masked_invalidr'r-r/can_castfloatrrr3squeeze issubdtypeintegerrr_logwarningclipr)rhighs rI_normalize_image_arrayz!_ImageBase._normalize_image_arrayst  % %ad 3 77bhh r{{177E;'O2177)<123 3 66Q;1772;!+ " A! qvv{qwwr{f/DnQWWI_EF F 66Q; --<3!Duuw{dQUUWn *EEGQUUW  GGAq$'ww"(("r}}QWWbjj'IHHRXX&rKct|tjjr t|}|j ||_d|_d|_y)z Set the image array. Note that this function does *not* update the normalization used. Parameters ---------- A : array-like or `PIL.Image.Image` NT)rOr+r, pil_to_arrayr>rrrrrs rIset_dataz_ImageBase.set_datas? a )QA--a0  rKc&|j|y)z Retained for backwards compatibility - use set_data instead. Parameters ---------- A : array-like N)rBrAs rI set_arrayz_ImageBase.set_arrays arKc|jS)aH Return the interpolation method the image uses when resizing. One of 'auto', 'antialiased', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', or 'none'. )_interpolationrs rIrzz_ImageBase.get_interpolations"""rKctj|dj}tjt |||_d|_y)a9 Set the interpolation method the image uses when resizing. If None, use :rc:`image.interpolation`. 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. Parameters ---------- s : {'auto', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'none'} or None zimage.interpolationrTN)r _val_or_rcrrrinterpolations_namesrFrrss rIrz_ImageBase.set_interpolations> NN13 4 : : < /qA rKc|jS)zy Return when interpolation happens during the transform to RGBA. One of 'data', 'rgba', 'auto'. )rrs rIget_interpolation_stagez"_ImageBase.get_interpolation_stages (((rKc~tj|d}tjgd|||_d|_y)a Set when interpolation happens during the transform to RGBA. Parameters ---------- s : {'data', 'rgba', 'auto'} or None Whether to apply up/downsampling interpolation in data or RGBA space. If None, use :rc:`image.interpolation_stage`. If 'auto' we will check upsampling rate and if less than 3 then use 'rgba', otherwise use 'data'. zimage.interpolation_stage)rCrr)rLTN)rrIrrrrrKs rIrz"_ImageBase.set_interpolation_stages5 NN19 : 3q9$%! rKcx|j}|jdk7xr|jxr |jS)z>Return whether the image can be composited with its neighbors.r)rrFr is_separable)rrFs rIrhz_ImageBase.can_composites=""$   6 )  OO     rKcLtj|d}||_d|_y)z Set whether image resampling is used. Parameters ---------- v : bool or None If None, use :rc:`image.resample`. zimage.resampleTN)rrIrr)rvs rIrz_ImageBase.set_resamples# NN1. / rKc|jS)z(Return whether image resampling is used.)rrs rIrz_ImageBase.get_resample s ~~rKc2t||_d|_y)z Set whether the resize filter normalizes the weights. See help for `~.Axes.imshow`. Parameters ---------- filternorm : bool TN)bool _filternormrrrs rIrz_ImageBase.set_filternorms + rKc|jS)z8Return whether the resize filter normalizes the weights.)rWrs rIrz_ImageBase.get_filternormsrKcVt|}|dkr td||_d|_y)z Set the resize filter radius only applicable to some interpolation schemes -- see help for imshow Parameters ---------- filterrad : positive float rz+The filter radius must be a positive numberTN)r6r _filterradr)rrrs rIrz_ImageBase.set_filterrads/ )  6JK K rKc|jS)zReturn the filterrad setting.)r[rs rIrz_ImageBase.get_filterrad.s rK)NNNNNT@F)rFTrF)%r __module__ __qualname____doc__zorderrrrrrrr2rrr0rrallow_rasterizationrUr%r0 staticmethodr>rBrDrzrrNrrhrrrrrr __classcell__rs@rIrPrPs F# &&*&:'<$  JM;?Z;xN(   !<$: @  #()"     rKrPc beZdZdZddddddddddd fd ZddZdd Zd Zd Zd Z d Z xZ S) AxesImagear An image with pixels on a regular grid, attached to an Axes. Parameters ---------- ax : `~matplotlib.axes.Axes` The Axes the image will belong to. cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap` The Colormap instance or registered colormap name used to map scalar data to colors. norm : str or `~matplotlib.colors.Normalize` Maps luminance to 0-1. interpolation : str, default: :rc:`image.interpolation` Supported values are 'none', 'auto', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos', 'blackman'. interpolation_stage : {'data', 'rgba'}, default: 'data' If 'data', interpolation is carried out on the data provided by the user. If 'rgba', the interpolation is carried out after the colormapping has been applied (visual interpolation). origin : {'upper', 'lower'}, default: :rc:`image.origin` Place the [0, 0] index of the array in the upper left or lower left corner of the Axes. The convention 'upper' is typically used for matrices and images. extent : tuple, optional The 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. filternorm : bool, default: True A parameter for the antigrain image resize filter (see the antigrain documentation). If filternorm is set, the filter normalizes integer values and corrects the rounding errors. It doesn't do anything with the source floating point values, it corrects only integers according to the rule of 1.0 which means that any sum of pixel weights must be equal to 1.0. So, the filter function must produce a graph of the proper shape. filterrad : float > 0, default: 4 The filter radius for filters that have a radius parameter, i.e. when interpolation is one of: 'sinc', 'lanczos' or 'blackman'. resample : bool, default: False When True, use a full resampling method. When False, only resample when the output image is larger than the input image. **kwargs : `~matplotlib.artist.Artist` properties NTr^F) rrrrrextentrrr*rc H||_t ||f||||||| | | d | y)N) rrrrrrrr*r)_extentrr)rrrrrrrrjrrr*rrrs rIrzAxesImage.__init__csF    '! 3  rKc|j\}}}}tj||||g}|j|j SrN)rlr from_extents transformedr)rr>r:x1r;y1rGs rIget_window_extentzAxesImage.get_window_extentsFBB  "b"b!12 2 2 455rKc|j}|j\}}}}ttj||g||gg} t | |} |j r(|jxs2|jjn|jdj} |j|j| | | ||S)NTrootr) rr&r r-r{rri get_clip_boxrrG get_figurerr) rr>r?rrFrpx2rqy2rGtransformed_bboxr<s rIr0zAxesImage.make_images""$*BBBHHr2hR123*47;?;K;K;M""$6 __$_/44 /? - D DrKc(|jdk(S)z9Return whether the image would be better drawn unsampled.r)rzrs rIrz AxesImage._check_unsampled_images%%'611rKc |jjd|d|dgfd|d|dgfg|\\}}\}}|rtjd||jj ||j }|jj ||j }|jj ||j }|jj ||j }||||g}||_||f||ff}|jj|||g|jjdd||g|jjdd|jjr|jj||fd |jjr|jj||fd d |_y) a Set the image extent. Parameters ---------- extent : 4-tuple of float The position and size of the image as tuple ``(left, right, bottom, top)`` in data coordinates. **kwargs Other parameters from which unit info (i.e., the *xunits*, *yunits*, *zunits* (for 3D Axes), *runits* and *thetaunits* (for polar Axes) entries are applied, if present. Notes ----- This updates `.Axes.dataLim`, and, if autoscaling, sets `.Axes.viewLim` to tightly fit the image, regardless of `~.Axes.dataLim`. Autoscaling state is not changed, so a subsequent call to `.Axes.autoscale_view` will redo the autoscaling in accord with `~.Axes.dataLim`. rDrr(rErtrs set_extentN)rT)r_process_unit_infor kwarg_error_validate_converted_limitsconvert_xunitsconvert_yunitsrlupdate_datalim sticky_edgesrDrEget_autoscalex_onset_xlimget_autoscaley_onset_ylimr)rrjrrrrrcornerss rIr}zAxesImage.set_extents*&*YY%A%AF1Ivay) *F1Ivay) * , &" tltT ""<8 8yy33 $%%'yy33 $%%'yy33 $%%'yy33 $%%'dD) ,t ,   )"&A"&A 99 & & ( II  d|$  7 99 & & ( II  d|$  7 rKc|j |jS|j}|\}}|jdk(r d|dz |dz dfSd|dz d|dz fS)6 D2.` >rKricxeZdZdZddfd ZdZddZdZdZfd Z d Z d Z d Z fd Z fdZdZxZS)NonUniformImagea An image with pixels on a rectilinear grid. In contrast to `.AxesImage`, where pixels are on a regular grid, NonUniformImage allows rows and columns with individual heights / widths. See also :doc:`/gallery/images_contours_and_fields/image_nonuniform`. rrHc Ht||fi||j|y)ae Parameters ---------- ax : `~matplotlib.axes.Axes` The Axes the image will belong to. interpolation : {'nearest', 'bilinear'}, default: 'nearest' The interpolation scheme used in the resampling. **kwargs All other keyword arguments are identical to those of `.AxesImage`. N)rrr)rrrrrs rIrzNonUniformImage.__init__s% &v& }-rKcy)z)Return False. Do not use unsampled image.Frrs rIrz&NonUniformImage._check_unsampled_imagesrKc |j td|r td|j}|jdk(rm|jt j k7r|j|d}nt j|ddddt jfdd}d|dddddf<n|jt j k7r"d|zjt j }|jddk(rZt jtg|jd ddt j }||ddddd df<d|dddddf<|}|jjj \}}}} t#t%|d zt%|d z z |z} t#t%| d zt%|d z z |z} |jj&j)} | j+t j,||| D cgc]} | |fc} ddd f}| j+t j,|| | Dcgc]}||fc}ddd f}|j.d k(r|j0dd |j0d dzdz }|j2dd |j2d dzdz }|j5|}|j5|}t j6|j9t j:j=t j>jA||jd z|j9t j jC| | df}nt jD|j0j5|d z d tG|j0dz }t jD|j2j5|d z d tG|j2dz }t j>jA||jd z|}t jDt jH||j0|z t jJ|j0|t jLd d }t jDt jH||j2|z t jJ|j2|t jLd d }t j@d |z d |z }t j@|d |z }t j@d |z |}t j@||}t jN| | dft j }tQdD]x}|dddd|fjCd }|||z}||||jd d|zz }|||d d|zz }||||jd d zd|zz }||dddd|f<z|||tSfScc} wcc}w)Nrz*unsampled not supported on NonUniformImagertTrr%rrsrrr(rrr&)*rrrrr'r-r/rrepeatnewaxisrr3r5tuplerrGextentsr6r\ transDatarr|linspacerF_Ax_Ay searchsortedascontiguousarrayviewuint32raveladdouterreshaper<r,divider~rr.ranger) rr>r?rrBr^r_r\rr8r7invertedTransformrDx_pixrEy_pixx_midy_midx_inty_intr!idx_intx_fracy_fracf00f10f01f11chanacbufs rIr0zNonUniformImage.make_image sK 77?CD D IJ J GG 66Q;ww"(("LL$L/IIa1bjj 011a8 !Q' ww"(("UNN288,wwqzQHHU#5QWWQq\#51#56A !Q!)  !Q' YY^^++ 1aeAhnqC8MIJuQx#~%(S.9]JK II//88:!++[[Au5 6aV 68891>!++[[Av6 7aV 799:A?   ) +XXcr]TXXab\1Q6EXXcr]TXXab\1Q6E&&u-E&&u-E $$Q',,RYY7==?FFLL!3U;=bhh(: ;  GG%%e,q0!S]Q5FHEGG%%e,q0!S]Q5FHEffll51771:#5u=GWW %$((5/12774883DU3K " ,1FWW %$((5/12774883DU3K " ,1F((1v:q6z2C((61v:.C((1v:v.C((66*C65!,bhh7Ba %q!Tz]**2.BwK'sR _W555sRVG_,,sR Q0999!$1a: %1a*,,,[ 7 7s  X< Yc|j|}tj|tj}tj|tj}|j|jcxk(rdk(r6n t d|j dd|j |j zk(s t d||_||_||_ d|_ d|_ y)a Set the grid for the pixel centers, and the pixel values. Parameters ---------- x, y : 1D array-like Monotonic arrays of shapes (N,) and (M,), respectively, specifying pixel centers. A : array-like (M, N) `~numpy.ndarray` or masked array of values to be colormapped, or (M, N, 3) RGB array, or (M, N, 4) RGBA array. r(NrtzAxes don't match array shapeT) r>r-r{rrr3rrrrrrrrDrErs rIrBzNonUniformImage.set_dataUs  ' ' * HHQ # HHQ #!&&%A%:; ;+,''"1+1779J*J:; ;  rKctdNzMethod not supportedrrargss rIrDzNonUniformImage.set_arraym!"899rKcF||dvr tdt| |y)z Parameters ---------- s : {'nearest', 'bilinear'} or None If None, use :rc:`image.interpolation`. N)rrz?Only nearest neighbor and bilinear interpolations are supported)rrr)rrLrs rIrz!NonUniformImage.set_interpolationps4 =Q&==%'NO O !!$rKc|j td|jd|jd|jd|jdfS)NzMust set data firstrr)rrrrrs rIr&zNonUniformImage.get_extent|sF 77?45 5xx{DHHRL$((1+txx|CCrKcyrNrrXs rIrzNonUniformImage.set_filternorm rKcyrNr)rrs rIrzNonUniformImage.set_filterradrrKcR|j tdt| |yNz'Cannot change colors after loading data)rrrset_norm)rrrs rIrzNonUniformImage.set_norm& 77 HI I rKcR|j tdt| |yr)rrrset_cmap)rrrs rIrzNonUniformImage.set_cmaprrKcr|j|j}}||jdks6||jdkDs$||jdks||jdkDryt j |j|dz }t j |j|dz }|j ||fSNrrr(xdataydatarrr-rrrrrDrErrs rIrzNonUniformImage.get_cursor_data{{EKK1  Oq488B</DHHQK1txx|#3 OODHHa (1 , OODHHa (1 ,wwq!t}rKr_)rr`rarbrrr0rBrDrr&rrrrrrfrgs@rIrrsL-6 .H-T0: %D     rKrcTeZdZdZ d ddddfd Zd dZdZdZdZd Z xZ S) PcolorImagez 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. N)rrrc zt ||||||j|||j|||yy)a Parameters ---------- ax : `~matplotlib.axes.Axes` The Axes the image will belong to. x, y : 1D array-like, optional Monotonic arrays of length N+1 and M+1, respectively, specifying rectangle boundaries. If not given, will default to ``range(N + 1)`` and ``range(M + 1)``, respectively. A : array-like The data to be color-coded. The interpretation depends on the shape: - (M, N) `~numpy.ndarray` or masked array: values to be colormapped - (M, N, 3): RGB array - (M, N, 4): RGBA array cmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap` The Colormap instance or registered colormap name used to map scalar data to colors. norm : str or `~matplotlib.colors.Normalize` Maps luminance to 0-1. **kwargs : `~matplotlib.artist.Artist` properties )rrrN)rrrrB) rrrDrErrrrrrs rIrzPcolorImage.__init__sDD $TYG f% = MM!Q " rKc|j td|r td|j;|j |jd}t j |gdd|_|j}tj|jjjd}t j|dzjt j}|d |k7jr|x|dd gddf<|dddd gf<|jjj \}}} } t#| d zt#|d z z } t#| d zt#|d z z } t#| |z} t#| |z} |jj$} t j&| j(| j*| }t j&| j,| j.| }|j0j3|}|j4j3|}|j7t j8j;t j<j?||j@d z|j7t jjC| | d f}|||tEfS)Nrz&unsampled not supported on PColorImageTr)r(r(rrrconstantrrrrrr(r%)#rrrrrr-padrrpatch get_facecolorr{rr/allrGrr\viewLimrr:rpr;rqrrrrrrrrr3rr)rr>r?rrpadded_Abgr^r_r\rr8r7vlrrrrr!s rIr0zPcolorImage.make_images- 77?CD D EF F ==  TWWD 1AFF1&> KDM== __TYY__:: @ T"((^GGVUA$67 1a*,,,rKcy)NFrrs rIrz"PcolorImage._check_unsampled_imagesrKc|j|}|&tjd|jddzn'tj|t j }|&tjd|jddzn'tj|t j }|jdd|jdz |jdz fk7r;td|jddd|jdz |jdz fd|d |dkr|ddd }|ddddd f}|d |dkr|ddd }|ddd }||_ ||_ ||_ d|_ d |_ y) az Set the grid for the rectangle boundaries, and the data values. Parameters ---------- x, y : 1D array-like, optional Monotonic arrays of length N+1 and M+1, respectively, specifying rectangle boundaries. If not given, will default to ``range(N + 1)`` and ``range(M + 1)``, respectively. A : array-like The data to be color-coded. The interpretation depends on the shape: - (M, N) `~numpy.ndarray` or masked array: values to be colormapped - (M, N, 3): RGB array - (M, N, 4): RGBA array Nrr(rrtz"Axes don't match array shape. Got z , expected .rT)r>r-aranger3r{r6rrVrrrrrrrs rIrBzPcolorImage.set_datasX$  ' ' *-.YBIIb!''!*q. )BHHQr?rrfacrGr8r7r<s rIr0zFigureImage.make_imageMsoo4o(ll377"dggck4773;/wws{TWW]]1%55ggckDGGMM!$44789++- v (,,aVeV_-. GGT4]S5Hu > >rKc2t||d|_y)zSet the image array.TN)rrBr)rrrs rIrBzFigureImage.set_data_s  rKr_) rr`rarbrcrFrr&r0rBrfrgs@rIrr#s=( FN!:7 >$rKrc LeZdZdZdddddddddfd Zd dZd Zd d ZxZS) BboxImagez;The Image class whose size is determined by the given bbox.NTr^Frrrrrrrr*c Ft | d|||||||| d| ||_y)rNrrN)rrrG) rrGrrrrrrrr*rrs rIrzBboxImage.__init__hsE$   '!   rKc||jj}t|jtr |jSt |jr|j|St d)NzUnknown type of bbox)rw _get_rendererrOrGr callabler)rr>s rIrrzBboxImage.get_window_extents\  (668H dii *99  dii 99X& &34 4rKc|j|s|jsdifS|j|j}}|j j ||}|ifS)r#F)r$rrDrErrr%)rr'rDrEr(s rIr%zBboxImage.containss[  ! !* -T5E5E5G"9 ||Z\\1'')221a8rzrKc:|j\}}|j|j}|xj||gzc_|j|}t ddg||gg}t ||_|j|j|||||S)Nrr) get_canvas_width_heightrrr_pointsr r _transformrr) rr>r?rr8r7bbox_inbbox_outr<s rIr0zBboxImage.make_images 88: v((299;E6?*))(3aVeV_-.)$/ GG Xt]i I IrKrNr_) rr`rarbrrrr%r0rfrgs@rIrres6E# @ 5 IrKrc ddlm}|t|trS|j |}t |j dkDrd}nxt|jjdd}nQt|drd}nBt|dr1t|jjjdd}nd}n|}|dk(rtjjntjj }t|tr2t |j |j dkDr t#d||5}t|tjjr t%|n t'|cdddS#1swYyxYw) a  Read an image from a file into an array. .. note:: This function exists for historical reasons. It is recommended to use `PIL.Image.open` instead for loading images. Parameters ---------- fname : str or file-like The image file to read: a filename, a URL or a file-like object opened in read-binary mode. Passing a URL is deprecated. Please open the URL for reading and pass the result to Pillow, e.g. with ``np.array(PIL.Image.open(urllib.request.urlopen(url)))``. format : str, optional The image file format assumed for reading the data. The image is loaded as a PNG file if *format* is set to "png", if *fname* is a path or opened file with a ".png" extension, or if it is a URL. In all other cases, *format* is ignored and the format is auto-detected by `PIL.Image.open`. Returns ------- `numpy.array` The image data. The returned array has shape - (M, N) for grayscale images. - (M, N, 3) for RGB images. - (M, N, 4) for RGBA images. PNG images are returned as float arrays (0-1). All other formats are returned as int arrays, with a bit depth determined by the file's contents. r)parseNr(r*geturlnamezPlease open the URL for reading and pass the result to Pillow, e.g. with ``np.array(PIL.Image.open(urllib.request.urlopen(url)))``.)urllibrrOstrurlparser,schemersuffixrhasattrrr+PngImagePlugin PngImageFiler,openr_pil_png_to_float_arrayr@)r/rwrparsedextimg_openrBs rIimreadr#sIN ~ eS !^^E*F6==!A%5k((..04 UH % C UF #uzz"))//1!"5CC+.%<''SYY^^ %#ennU&;&B&B"Ca"G I  %%EeS%7%7%D%DE(.U#%%%s :FF )metadata pil_kwargsc ddlm} tj|}t |t j rt j|}|It |trt|jddntjdj}|dvrH| td|| |d } | j|||||d | j!|||d | y|tjd }nt#j$d||dk(r|ddd}t |t&r3|j(dk(r$|j*dk(r|j,ddk(r|} n;t/j0|} | j3||| j5|d } | i} n| j7} | j,d| j,df}tj8| d} t:j<j?d|| dddd}|dk(rd| vr|rt#j@dn}ddtjBd i||ni}t:jDjGx| d<}|jID]\}}| |jK||n|td!||d"vrd#}tjd$}tMjN|d%rtjd&}tQd'tSjT|D}t:j<jWd(||}|jY|||}| j[d)|| j[d*||f|j\|fi| y)+ae Colormap and save an array as an image file. RGB(A) images are passed through. Single channel images will be colormapped according to *cmap* and *norm*. .. note:: If you want to save a single channel image as gray scale please use an image I/O library (such as pillow, tifffile, or imageio) directly. Parameters ---------- fname : str or path-like or file-like A path or a file-like object to store the image in. If *format* is not set, then the output format is inferred from the extension of *fname*, if any, and from :rc:`savefig.format` otherwise. If *format* is set, it determines the output format. arr : array-like The image data. Accepts NumPy arrays or sequences (e.g., lists or tuples). The shape can be one of MxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA). vmin, vmax : float, optional *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 : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap` A Colormap instance or registered colormap name. The colormap maps scalar data to colors. It is ignored for RGB(A) data. format : str, optional The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when this is unset is documented under *fname*. origin : {'upper', 'lower'}, default: :rc:`image.origin` Indicates whether the ``(0, 0)`` index of the array is in the upper left or lower left corner of the Axes. dpi : float The DPI to store in the metadata of the file. This does not affect the resolution of the output image. Depending on file format, this may be rounded to the nearest integer. metadata : dict, optional Metadata in the image file. The supported keys depend on the output format, see the documentation of the respective backends for more information. Currently only supported for "png", "pdf", "ps", "eps", and "svg". pil_kwargs : dict, optional Keyword arguments passed to `PIL.Image.Image.save`. If the 'pnginfo' key is present, it completely overrides *metadata*, including the default 'Software' key. rFigureNr(zsavefig.format)pdfpsepssvgz'Cannot use 'pil_kwargs' when saving to F)rframeonT)rvminvmaxrresize)rrw transparentr$r)rrrrrrrsr%)rrC) requirementsRGBArawr*pnginfoz@'metadata' is overridden by the 'pnginfo' entry in 'pil_kwargs'.SoftwarezMatplotlib versionz, https://matplotlib.org/z"metadata not supported for format )jpgjpegr9zsavefig.facecolorrzfigure.facecolorc38K|]}t|dzyw)rN)r6rQs rIrSzimsave..ssJ1#a#g,JsRGBrwr)/matplotlib.figurer(r- asanyarrayrOosPathLikefspathrrrrrrrfigimagesavefigrr memoryviewrwrr3 mcolorizer Colorizerset_climrr2requirer+r, frombufferr __version__rPngInfoitemsadd_textr _str_equalrrto_rgbnewpaste setdefaultr.)r/rr.r/rrwrrr$r%r(rrsm pil_shaperBr6krS facecolorcolor backgrounds rIimsaverXs`h) -- C%% %  ~,6uc,B$u+$$QR(||$45uuw  ,,  !9&BD De, St$T&   " Es6t%  ' >\\.1F   1& A W dd)C sJ 'CJJ#,=HHMciimq&8 D%%40B KKd #::c:.D  J$*JZZ]DJJqM2 zz$S1 $$ ItUFAq: U?J&&&(JK#5coo5FG;"<$,#7xR 362D2D2L2L2NN 9%$NN,/DAq}((A./ !A&LM M _ $F %89I 62LL);< Jy0IJJEui?J   UE *Eh/ec3Z0 5'J'rKc.|jdvrtj|S|jjdr|j d|j}|jj drtj |d}ntj |d}|j|jdddjd S |jd }tj|S#t$r}td |d}~wwxYw) a` Load a `PIL image`_ and return it as a numpy int array. .. _PIL image: https://pillow.readthedocs.io/en/latest/reference/Image.html Returns ------- numpy.array The array shape depends on the image type: - (M, N) for grayscale images. - (M, N, 3) for RGB images. - (M, N, 4) for RGBA images. )r4RGBXr;LzI;16r5rz>u2z''/Hzz(## >34# = >sC:: D DDc|j}|jj}|dk(r$tj|tj S|dk(r&tj |dtj S|dk(r&tj |dtj S|dk(r&tj |dtj S|d k(r&tj |d tj S|d k(r&tj |dtj S|d k(r5tj |jd dtj S|dk(r5tj |jd dtj S|d k(r&tj |dtj Std|)z2Convert a PIL `PNGImageFile` to a 0-1 float array.1zL;2rsr&zL;4r[rzI;16Bir;Pr4LAzUnknown PIL rawmode: ) r\r* im_rawmoder-r]rrrar)pil_pngr\rawmodes rIrrsP <> u}yy("**== s{yy0("**MM t|yy0("**MM v~yy("**== ,WI6 77rKcVt|}|j\}}}d} || z |z} || z |z} |rddlm} | j | | f| } nddlm}|| | f| } t| | jgdddgg }|j|dd | | j|| | S) a Make a thumbnail of image in *infile* with output filename *thumbfile*. See :doc:`/gallery/misc/image_thumbnail_sgskip`. Parameters ---------- infile : str or file-like The image file. Matplotlib relies on Pillow_ for image reading, and thus supports a wide range of file formats, including PNG, JPG, TIFF and others. .. _Pillow: https://python-pillow.github.io thumbfile : str or file-like The thumbnail filename. scale : float, default: 0.1 The scale factor for the thumbnail. interpolation : str, default: 'bilinear' The interpolation scheme used in the resampling. See the *interpolation* parameter of `~.Axes.imshow` for possible values. preview : bool, default: False If True, the default backend (presumably a user interface backend) will be used which will cause a figure to be raised if `~matplotlib.pyplot.show` is called. If it is False, the figure is created using `.FigureCanvasBase` and the drawing backend is selected as `.Figure.savefig` would normally do. Returns ------- `.Figure` The figure instance containing the thumbnail. drN)figsizerr')rrr(r(rF)aspectr-xticksyticksT)ror*r)r) r#r3matplotlib.pyplotpyplotfigurer<r(radd_axesimshowrB)infile thumbfileryrpreviewr!rowscolsdepthrr7r8pltrr(rs rI thumbnailr~sN BD$ C CZ% F 3J E'jj%cj:,eV_#6 l6#Br  ;BIIb$mILKK sK# JrK)rrN)NNNNNrm)g?rF)Lrbrr>loggingpathlibrrunumpyr- PIL.Imager+PIL.PngImagePlugin matplotlibrrrrmatplotlib._imagematplotlib.artistartistrmatplotlib.colorizerrrDmatplotlib.backend_basesrmatplotlib.colorscolorsrmatplotlib.transformsr r r r r rr getLoggerrr:r<BILINEARBICUBICSPLINE16SPLINE36HANNINGHAMMINGHERMITEKAISERQUADRICCATROMGAUSSIANBESSELMITCHELLSINCLANCZOSBLACKMANrsetrJrJrorrColorizingArtistrPrirrrrr#rXr@rr~rrKrIrs]  " #)5#(((w"  FNN  FNN v~~    v~~      v~~ v~~ v~~  fmm v~~  fmm   fmm  ! " FKK# $~~>>)  .9~5Dr7;,`<@q5p G ,,G Ty yxjijZD)DN?*?D@I @IFK%\@DC(-1dC(L $F8<;E=rK