如何在matplotlib中“关闭" imshow()的模糊效果? [英] How to 'turn off' blurry effect of imshow() in matplotlib?

查看:294
本文介绍了如何在matplotlib中“关闭" imshow()的模糊效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个概率图,但是imshow会为概率为零的点生成模糊值.如何摆脱真实网格点周围的模糊边缘?

I want to make a color plot of probabilities however imshow generates blurry values for points which have zero probability. How can I get rid of this blurry periphery around real grid points?

示例:

import numpy as np
import matplotlib.pyplot as plt

a=np.asarray([[  0.00000000e+00 , 1.05824446e-01 ,  2.05086136e-04,   0.00000000e+00],
[  1.05824446e-01 ,  3.15012305e-01  , 1.31255127e-01  , 1.05209188e-01],
 [  2.05086136e-04  , 1.31255127e-01 ,  0.00000000e+00 ,  0.00000000e+00],
 [  0.00000000e+00   ,1.05209188e-01  , 0.00000000e+00  , 0.00000000e+00]])
im=plt.imshow(a,extent=[0,4,0,4],origin='lower',alpha=1,aspect='auto')
plt.show()

推荐答案

默认情况下(在mpl 2.0中进行了更改),imshow对数据进行插值(就像对图像所做的那样).您需要做的就是告诉它不要插值:

By default (which is changed mpl 2.0), imshow interpolates the data (as you would want to do for an image). All you need to do is tell it to not interpolate:

im = plt.imshow(..., interpolation='none')

'nearest'也将适用于您想要的内容.参见像素之间的平滑像matplotlib imshow 这样的matlab中的imagesc \ imshow 的示例.

'nearest' will also work for what you want. See smoothing between pixels of imagesc\imshow in matlab like the matplotlib imshow for examples of all of the kinds of interpolation.

文档

这篇关于如何在matplotlib中“关闭" imshow()的模糊效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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