何时在pcolormesh上使用imshow? [英] When to use imshow over pcolormesh?

查看:173
本文介绍了何时在pcolormesh上使用imshow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常发现自己需要使用matplotlib在Python中创建热图样式的可视化文件. Matplotlib提供了几种功能,它们显然可以完成相同的操作.建议使用pcolormesh代替pcolor,但是imshowpcolormesh之间有什么区别(从实际的角度来看,作为数据绘图仪)?互相使用时有什么优点/缺点?在哪种情况下,一个或另一个将是明显的赢家?

I often find myself needing to create heatmap-style visualizations in Python with matplotlib. Matplotlib provides several functions which apparently do the same thing. pcolormesh is recommended instead of pcolor but what is the difference (from a practical point of view as a data plotter) between imshow and pcolormesh? What are the pros/cons of using one over the other? In what scenarios would one or the other be a clear winner?

推荐答案

从根本上讲,imshow假定数组中的所有数据元素都将以相同的大小呈现,而pcolormesh/pcolor则将具有矩形元素的数据数组,其大小可能会在矩形网格上变化.

Fundamentally, imshow assumes that all data elements in your array are to be rendered at the same size, whereas pcolormesh/pcolor associates elements of the data array with rectangular elements whose size may vary over the rectangular grid.

如果您的网格元素是均匀的,则将imshow的插值设置为最近"将看起来与默认的pcolormesh显示非常相似(没有可选的XY args).明显的区别是imshow y轴将反转(w.r.t. pcolormesh)并保持宽高比,尽管这些特征也可以更改为类似pcolormesh输出的样子.

If your mesh elements are uniform, then imshow with interpolation set to "nearest" will look very similar to the default pcolormesh display (without the optional X and Y args). The obvious differences are that the imshow y-axis will be inverted (w.r.t. pcolormesh) and the aspect ratio is maintained, although those characteristics can be altered to look like the pcolormesh output as well.

从实际的角度来看,如果要将数据数组可视化为单元格,尤其是在矩形网格不均匀或要绘制单元格的边界/边缘时,pcolormesh更为方便.否则,如果您具有固定的像元大小,想要保持宽高比,想要控制像素插值或想要直接指定RGB值,则imshow会更方便.

From a practical point of view, pcolormesh is more convenient if you want to visualize the data array as cells, particularly when the rectangular mesh is non-uniform or when you want to plot the boundaries/edges of the cells. Otherwise, imshow is more convenient if you have a fixed cell size, want to maintain aspect ratio, want control over pixel interpolation, or want to specify RGB values directly.

这篇关于何时在pcolormesh上使用imshow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆