matplotlib中matshow和imshow的区别

2023-10-25 08:40

本文主要是介绍matplotlib中matshow和imshow的区别,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

matplotlib中matshow和imshow的区别

1.matshow

如下,即在一个图形窗口中将数组作为矩阵展示

def matshow(A, fignum=None, **kwargs):"""Display an array as a matrix in a new figure window.The origin is set at the upper left hand corner and rows (firstdimension of the array) are displayed horizontally.  The aspectratio of the figure window is that of the array, unless this wouldmake an excessively short or narrow figure.Tick labels for the xaxis are placed on top.Parameters----------A : array-like(M, N)The matrix to be displayed.fignum : None or int or FalseIf *None*, create a new figure window with automatic numbering.If a nonzero integer, draw into the figure with the given number(create it if it does not exist).If 0, use the current axes (or create one if it does not exist)... note::Because of how `.Axes.matshow` tries to set the figure aspectratio to be the one of the array, strange things may happen if youreuse an existing figure.Returns-------image : `~matplotlib.image.AxesImage`Other Parameters----------------**kwargs : `~matplotlib.axes.Axes.imshow` arguments"""

效果图如下:

2.imshow

展示图像数据在一个二维普通光栅中

    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.Parameters----------X : array-like or PIL imageThe image data. Supported array shapes are:- (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).- (M, N, 4): an image with RGBA values (0-1 float or 0-255 int),i.e. including transparency.The first two dimensions (M, N) define the rows and columns ofthe image.Out-of-range RGB(A) values are clipped.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`.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.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.This parameter is a shortcut for explicitly calling`.Axes.set_aspect`. See there for further details.- 'equal': Ensures an aspect ratio of 1. Pixels will be square(unless pixel sizes are explicitly made non-square in datacoordinates using *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').interpolation : str, optionalThe interpolation method used. If *None*:rc:`image.interpolation` is used, which defaults to 'nearest'.Supported values are 'none', 'nearest', 'bilinear', 'bicubic','spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser','quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc','lanczos'.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.See:doc:`/gallery/images_contours_and_fields/interpolation_methods`for an overview of the supported 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*.alpha : scalar, optionalThe alpha blending value, between 0 (transparent) and 1 (opaque).This parameter is ignored for RGBA input data.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.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'.Note that the vertical axes points upward for 'lower'but downward for 'upper'.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.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.Note that the direction of the vertical axis and thus the defaultvalues for top and bottom depend on *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 example :doc:`/tutorials/intermediate/imshow_extent` for amore 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.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'.resample : bool, optionalWhen *True*, use a full resampling method.  When *False*, onlyresample when the output image is larger than the input image.url : str, optionalSet the url of the created `.AxesImage`. See `.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.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).There are two common representations for RGB images with an alphachannel:-   Straight (unassociated) alpha: R, G, and B channels represent thecolor of the pixel, disregarding its opacity.-   Premultiplied (associated) alpha: R, G, and B channels representthe color of the pixel, adjusted for its opacity by multiplication.`~matplotlib.pyplot.imshow` expects RGB images adopting the straight(unassociated) alpha representation."""

同一个矩阵展示效果如下:

与上面对比我们可以看到图像的坐标默认是不同的。

 

详细可参阅官方文档。

https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.matshow.html#matplotlib.axes.Axes.matshow

https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.imshow.html#matplotlib.axes.Axes.imshow

 

 

这篇关于matplotlib中matshow和imshow的区别的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/281380

相关文章

Go之errors.New和fmt.Errorf 的区别小结

《Go之errors.New和fmt.Errorf的区别小结》本文主要介绍了Go之errors.New和fmt.Errorf的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考... 目录error的基本用法1. 获取错误信息2. 在条件判断中使用基本区别1.函数签名2.使用场景详细对

Redis中哨兵机制和集群的区别及说明

《Redis中哨兵机制和集群的区别及说明》Redis哨兵通过主从复制实现高可用,适用于中小规模数据;集群采用分布式分片,支持动态扩展,适合大规模数据,哨兵管理简单但扩展性弱,集群性能更强但架构复杂,根... 目录一、架构设计与节点角色1. 哨兵机制(Sentinel)2. 集群(Cluster)二、数据分片

一文带你迅速搞懂路由器/交换机/光猫三者概念区别

《一文带你迅速搞懂路由器/交换机/光猫三者概念区别》讨论网络设备时,常提及路由器、交换机及光猫等词汇,日常生活、工作中,这些设备至关重要,居家上网、企业内部沟通乃至互联网冲浪皆无法脱离其影响力,本文将... 当谈论网络设备时,我们常常会听到路由器、交换机和光猫这几个名词。它们是构建现代网络基础设施的关键组成

redis和redission分布式锁原理及区别说明

《redis和redission分布式锁原理及区别说明》文章对比了synchronized、乐观锁、Redis分布式锁及Redission锁的原理与区别,指出在集群环境下synchronized失效,... 目录Redis和redission分布式锁原理及区别1、有的同伴想到了synchronized关键字

JAVA覆盖和重写的区别及说明

《JAVA覆盖和重写的区别及说明》非静态方法的覆盖即重写,具有多态性;静态方法无法被覆盖,但可被重写(仅通过类名调用),二者区别在于绑定时机与引用类型关联性... 目录Java覆盖和重写的区别经常听到两种话认真读完上面两份代码JAVA覆盖和重写的区别经常听到两种话1.覆盖=重写。2.静态方法可andro

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤

C++中全局变量和局部变量的区别

《C++中全局变量和局部变量的区别》本文主要介绍了C++中全局变量和局部变量的区别,全局变量和局部变量在作用域和生命周期上有显著的区别,下面就来介绍一下,感兴趣的可以了解一下... 目录一、全局变量定义生命周期存储位置代码示例输出二、局部变量定义生命周期存储位置代码示例输出三、全局变量和局部变量的区别作用域

MyBatis中$与#的区别解析

《MyBatis中$与#的区别解析》文章浏览阅读314次,点赞4次,收藏6次。MyBatis使用#{}作为参数占位符时,会创建预处理语句(PreparedStatement),并将参数值作为预处理语句... 目录一、介绍二、sql注入风险实例一、介绍#(井号):MyBATis使用#{}作为参数占位符时,会

Android kotlin中 Channel 和 Flow 的区别和选择使用场景分析

《Androidkotlin中Channel和Flow的区别和选择使用场景分析》Kotlin协程中,Flow是冷数据流,按需触发,适合响应式数据处理;Channel是热数据流,持续发送,支持... 目录一、基本概念界定FlowChannel二、核心特性对比数据生产触发条件生产与消费的关系背压处理机制生命周期

Javaee多线程之进程和线程之间的区别和联系(最新整理)

《Javaee多线程之进程和线程之间的区别和联系(最新整理)》进程是资源分配单位,线程是调度执行单位,共享资源更高效,创建线程五种方式:继承Thread、Runnable接口、匿名类、lambda,r... 目录进程和线程进程线程进程和线程的区别创建线程的五种写法继承Thread,重写run实现Runnab