python matplotlib.pyplot.imshow() (在2D常规栅格上显示图像(数据))
生活随笔
收集整理的這篇文章主要介紹了
python matplotlib.pyplot.imshow() (在2D常规栅格上显示图像(数据))
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
from pyplot.py
# Autogenerated by boilerplate.py. Do not edit as changes will be lost. # 由boilerplate.py自動生成。 請勿編輯,因為更改將丟失。 @docstring.copy(Axes.imshow) def imshow(X, cmap=None, norm=None, aspect=None, interpolation=None,alpha=None, vmin=None, vmax=None, origin=None, extent=None,shape=cbook.deprecation._deprecated_parameter, filternorm=1,filterrad=4.0, imlim=cbook.deprecation._deprecated_parameter,resample=None, url=None, *, data=None, **kwargs):__ret = gca().imshow(X, cmap=cmap, norm=norm, aspect=aspect,interpolation=interpolation, alpha=alpha, vmin=vmin,vmax=vmax, origin=origin, extent=extent, shape=shape,filternorm=filternorm, filterrad=filterrad, imlim=imlim,resample=resample, url=url, **({"data": data} if data is notNone else {}), **kwargs)sci(__ret)return __retfrom _axes.py
#### plotting z(x,y): imshow, pcolor and relatives, contour 繪制z(x,y):imshow,pcolor和相關的,輪廓@_preprocess_data()@cbook._delete_parameter("3.1", "shape")@cbook._delete_parameter("3.1", "imlim")def imshow(self, X, cmap=None, norm=None, aspect=None,interpolation=None, alpha=None, vmin=None, vmax=None,origin=None, extent=None, shape=None, filternorm=1,filterrad=4.0, imlim=None, resample=None, url=None, **kwargs):"""Display an image, i.e. data on a 2D regular raster.在2D常規柵格上顯示圖像,即數據。Parameters----------X : array-like or PIL imageThe image data. Supported array shapes are:陣列狀或PIL圖像圖像數據。 支持的數組形狀為:- (M, N): an image with scalar data. The data is visualizedusing a colormap.具有標量數據的圖像。 數據使用顏色圖可視化。- (M, N, 3): an image with RGB values (0-1 float or 0-255 int).具有RGB值(0-1浮點或0-255整數)的圖像。- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),i.e. including transparency.具有RGBA值(0-1浮點或0-255整數)的圖像,即包括透明度。The first two dimensions (M, N) define the rows and columns ofthe image.前兩個維度(M,N)定義圖像的行和列。Out-of-range RGB(A) values are clipped. 超出范圍的RGB(A)值將被裁剪。cmap : str or `~matplotlib.colors.Colormap`, optionalThe Colormap instance or registered colormap name used to mapscalar data to colors. This parameter is ignored for RGB(A) data.Defaults to :rc:`image.cmap`.str或?matplotlib.colors.Colormap`,可選用于將標量數據映射到顏色的Colormap實例或注冊的顏色圖名稱。 對于RGB(A)數據,將忽略此參數。默認為:rc.`image.cmap`。norm : `~matplotlib.colors.Normalize`, optionalThe `Normalize` instance used to scale scalar data to the [0, 1]range before mapping to colors using *cmap*. By default, a linearscaling mapping the lowest value to 0 and the highest to 1 is used.This parameter is ignored for RGB(A) data.?matplotlib.colors.Normalize,可選在使用* cmap *映射到顏色之前,“ Normalize”實例用于將標量數據縮放到[0,1]范圍。 默認情況下,使用線性比例將最小值映射到0,將最大值映射到1。對于RGB(A)數據,將忽略此參數。aspect : {'equal', 'auto'} or float, optionalControls the aspect ratio of the axes. The aspect is of particularrelevance for images since it may distort the image, i.e. pixelwill not be square.{'equal','auto'}或float,可選控制軸的縱橫比。 該方面與圖像特別相關,因為它可能使圖像失真,即像素將不會是正方形的。This parameter is a shortcut for explicitly calling`.Axes.set_aspect`. See there for further details.這個參數是顯式調用`.Axes.set_aspect`的快捷方式。 有關更多詳細信息,請參見此處。- 'equal': Ensures an aspect ratio of 1. Pixels will be square(unless pixel sizes are explicitly made non-square in datacoordinates using *extent*).確保縱橫比為1。像素將為正方形(除非使用* extent *在數據坐標中將像素大小明確地設為非正方形)。- 'auto': The axes is kept fixed and the aspect is adjusted sothat the data fit in the axes. In general, this will result innon-square pixels.軸保持固定,并且調整了寬高比,以使數據適合軸。 通常,這將導致非正方形像素。If not given, use :rc:`image.aspect` (default: 'equal').如果未給出,請使用image.aspect(默認值:等于)。interpolation : str, optionalThe interpolation method used. If *None*:rc:`image.interpolation` is used, which defaults to 'nearest'.str,可選使用的插值方法。 如果使用* None *:rc:`image.interpolation`,則默認為'nearest'。Supported values are 'none', 'nearest', 'bilinear', 'bicubic','spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser','quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc','lanczos'.支持的值是“ none”,“ nearest”,“ bilinear”,“ bicubic”,“ spline16”,“ spline36”,“ hanning”,“ hamming”,“ hermite”,“ kaiser”,“ quadric”,“ catrom” ,“高斯”,“貝塞爾”,“米切爾”,“辛克”,“蘭科斯”。If *interpolation* is 'none', then no interpolation is performedon the Agg, ps, pdf and svg backends. Other backends will fall backto 'nearest'. Note that most SVG renders perform interpolation atrendering and that the default interpolation method they implementmay differ.如果* interpolation *為'none',則不會在Agg,ps,pdf和svg后端上執行插值。 其他后端將回落到“最近”。 請注意,大多數SVG渲染都會在渲染時執行插值,并且它們實現的默認插值方法可能有所不同。See:doc:`/gallery/images_contours_and_fields/interpolation_methods`for an overview of the supported interpolation methods.:doc:`/ gallery / images_contours_and_fields / interpolation_methods`可以大致了解所支持的插值方法。Some interpolation methods require an additional radius parameter,which can be set by *filterrad*. Additionally, the antigrain imageresize filter is controlled by the parameter *filternorm*.某些插值方法需要附加的半徑參數,可以由* filterrad *設置。 此外,防顆粒圖像調整大小濾鏡由參數* filternorm *控制。alpha : scalar, optionalThe alpha blending value, between 0 (transparent) and 1 (opaque).This parameter is ignored for RGBA input data.標量,可選Alpha混合值,介于0(透明)和1(不透明)之間。對于RGBA輸入數據,將忽略此參數。vmin, vmax : scalar, optionalWhen using scalar data and no explicit *norm*, *vmin* and *vmax*define the data range that the colormap covers. By default,the colormap covers the complete value range of the supplieddata. *vmin*, *vmax* are ignored if the *norm* parameter is used.標量,可選當使用標量數據并且沒有明確的* norm *時,* vmin *和* vmax *定義顏色圖覆蓋的數據范圍。 默認情況下,顏色圖覆蓋所提供數據的完整值范圍。 如果使用* norm *參數,則* vmin *,* vmax *將被忽略。origin : {'upper', 'lower'}, optionalPlace the [0,0] index of the array in the upper left or lower leftcorner of the axes. The convention 'upper' is typically used formatrices and images.If not given, :rc:`image.origin` is used, defaulting to 'upper'.可選的將數組的[0,0]索引放置在軸的左上角或左下角。 約定“ upper”通常用于矩陣和圖像。 如果未指定,則使用image.origin,默認為'upper'。Note that the vertical axes points upward for 'lower'but downward for 'upper'.請注意,垂直軸指向上方表示“下方”,但指向下方表示“上方”。See the :doc:`/tutorials/intermediate/imshow_extent` tutorial forexamples and a more detailed description.doc:`/ tutorials / intermediate / imshow_extent`教程中的示例和更詳細的描述。extent : scalars (left, right, bottom, top), optionalThe bounding box in data coordinates that the image will fill.The image is stretched individually along x and y to fill the box.可選的數據將要填充的數據中的邊界框。圖像分別沿x和y拉伸以填充框。The default extent is determined by the following conditions.Pixels have unit size in data coordinates. Their centers are oninteger coordinates, and their center coordinates range from 0 tocolumns-1 horizontally and from 0 to rows-1 vertically.默認范圍由以下條件決定。像素在數據坐標中具有單位大小。 它們的中心在整數坐標上,并且其中心坐標的范圍從水平0到列1,垂直從0到行1。Note that the direction of the vertical axis and thus the defaultvalues for top and bottom depend on *origin*:請注意,垂直軸的方向以及頂部和底部的默認值取決于* origin *:- For ``origin == 'upper'`` the default is``(-0.5, numcols-0.5, numrows-0.5, -0.5)``.- For ``origin == 'lower'`` the default is``(-0.5, numcols-0.5, -0.5, numrows-0.5)``.See the :doc:`/tutorials/intermediate/imshow_extent` tutorial forexamples and a more detailed description.filternorm : bool, optional, default: TrueA parameter for the antigrain image resize filter (see theantigrain documentation). If *filternorm* is set, the filternormalizes integer values and corrects the rounding errors. Itdoesn't do anything with the source floating point values, itcorrects only integers according to the rule of 1.0 which meansthat any sum of pixel weights must be equal to 1.0. So, thefilter function must produce a graph of the proper shape.bool,可選,默認值:True抗紋理圖像調整大小過濾器的參數(請參閱抗紋理文檔)。 如果設置了* filternorm *,則過濾器將對整數值進行歸一化并糾正舍入誤差。 它對源浮點值不做任何事情,它僅根據1.0的規則校正整數,這意味著任何像素權重之和必須等于1.0。因此,過濾器功能必須產生適當形狀的圖形。filterrad : float > 0, optional, default: 4.0The filter radius for filters that have a radius parameter, i.e.when interpolation is one of: 'sinc', 'lanczos' or 'blackman'.float> 0,可選,默認值:4.0具有半徑參數的濾鏡的濾鏡半徑,即當插值是“ sinc”,“ lanczos”或“ blackman”之一時。resample : bool, optionalWhen *True*, use a full resampling method. When *False*, onlyresample when the output image is larger than the input image.布爾值,可選當為“真”時,請使用完整的重采樣方法。 當* False *時,僅當輸出圖像大于輸入圖像時才重新采樣。url : str, optionalSet the url of the created `.AxesImage`. See `.Artist.set_url`.str,可選設置創建的`.AxesImage`的網址。 參見`.Artist.set_url`。Returns-------image : `~matplotlib.image.AxesImage`Other Parameters----------------**kwargs : `~matplotlib.artist.Artist` propertiesThese parameters are passed on to the constructor of the`.AxesImage` artist.這些參數被傳遞給`.AxesImage`藝術家的構造函數。See also--------matshow : Plot a matrix or an array as an image.Notes-----Unless *extent* is used, pixel centers will be located at integercoordinates. In other words: the origin will coincide with the centerof pixel (0, 0).除非使用* extent *,否則像素中心將位于整數坐標處。 換句話說:原點將與像素(0,0)的中心重合。There are two common representations for RGB images with an alphachannel:具有alpha通道的RGB圖像有兩種常見表示形式:- Straight (unassociated) alpha: R, G, and B channels represent thecolor of the pixel, disregarding its opacity.直(無關聯)alpha:R,G和B通道代表像素的顏色,而忽略其不透明度。- Premultiplied (associated) alpha: R, G, and B channels representthe color of the pixel, adjusted for its opacity by multiplication.預乘(關聯)的alpha:R,G和B通道表示像素的顏色,通過乘法對其像素的不透明度進行了調整。`~matplotlib.pyplot.imshow` expects RGB images adopting the straight(unassociated) alpha representation.?matplotlib.pyplot.imshow`期望RGB圖像采用直接(未關聯)的alpha表示。"""if norm is not None and not isinstance(norm, mcolors.Normalize):raise ValueError("'norm' must be an instance of 'mcolors.Normalize'")if aspect is None:aspect = rcParams['image.aspect']self.set_aspect(aspect)im = mimage.AxesImage(self, cmap, norm, interpolation, origin, extent,filternorm=filternorm, filterrad=filterrad,resample=resample, **kwargs)im.set_data(X)im.set_alpha(alpha)if im.get_clip_path() is None:# image does not already have clipping set, clip to axes patchim.set_clip_path(self.patch)if vmin is not None or vmax is not None:im.set_clim(vmin, vmax)else:im.autoscale_None()im.set_url(url)# update ax.dataLim, and, if autoscaling, set viewLim# to tightly fit the image, regardless of dataLim.im.set_extent(im.get_extent())self.add_image(im)return im注:在pycharm上調用了imshow()函數后,圖像還是沒法打印,后來加了plt.show()函數后,就好了。。。
總結
以上是生活随笔為你收集整理的python matplotlib.pyplot.imshow() (在2D常规栅格上显示图像(数据))的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx 正向代理与反向代理区别
- 下一篇: websocket python爬虫_p