防止在matplotlib中为imshow进行抗锯齿 [英] Prevent anti-aliasing for imshow in matplotlib

查看:175
本文介绍了防止在matplotlib中为imshow进行抗锯齿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用matplotlib的imshow()方法表示一个小的numpy矩阵时,最终会在像素之间进行一些平滑处理.有什么方法可以禁用此功能吗? 绘制的28x28矩阵

When I use matplotlib's imshow() method to represent a small numpy matrix, it ends up doing some smoothing between pixels. Is there any way to disables this? It makes my figure's misleading in presentations.

上图是一个28x28的图像,所以我应该看到代表每个像素的单色大正方形(如matlab在使用imagesc()时将其显示).但是相反,像素似乎被相邻像素模糊了.有没有办法禁用此行为?

The figure above is a 28x28 image, so I should be seeing large squares of single colors representing each pixel (as matlab would display it when using imagesc()). But Instead, the pixels seem to be blurred with neighboring pixels. Is there a way to disable this behavior?

推荐答案

imshow有一个插值选项,用于控制如何以及是否将插值应用于矩阵渲染.如果您尝试

There is an interpolation option for imshow which controls how and if interpolation will be applied to the rendering of the matrix. If you try

imshow(array, interpolation="nearest") 

您可能会得到更多您想要的东西.例如

you might get something more like you want. As an example

A=10*np.eye(10) + np.random.rand(100).reshape(10,10)
imshow(A)

A=10*np.eye(10) + np.random.rand(100).reshape(10,10)
imshow(A, interpolation="nearest")

这篇关于防止在matplotlib中为imshow进行抗锯齿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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