如何使用Mathplot IMShow显示一个白色像素 [英] How display one white pixel with mathplot imshow

查看:44
本文介绍了如何使用Mathplot IMShow显示一个白色像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 mathplot 显示一个白色像素:

I want to display one white pixel with mathplot:

import numpy as np
import matplotlib.pyplot as plt
plt.imshow([[0.99]], cmap='gray', interpolation='nearest')
plt.show()

,但显示为黑色.为什么?

but it shows black. Why?

推荐答案

问题是你只给 imshow 一个值,所以色标围绕该值设置,它被绘制为刻度的最小值(因此为黑色).

The problem is that you only give imshow one value, so the colour scale is set around that value and it gets painted as the minimum value of the scale (thus black).

指定 vminvmax,如此处所示:

Specify vmin and vmax, as shown here:

import numpy as np
import matplotlib.pyplot as plt
plt.imshow([[0.99]], cmap='gray', interpolation='nearest', vmin=0, vmax=1)
plt.show()

更重要的是,您需要将 vmax 映射为白色,将其作为 imshow 的值,并将 vmin 设置为小于:

More importantly, you need vmax, which will be mapped to white, to be the value you give imshow, and vmin to be smaller than that:

import numpy as np
import matplotlib.pyplot as plt

max_value = np.random.random()
min_value = -max_value # for instance

plt.imshow([[max_value]], cmap='gray', interpolation='nearest',
           vmin=min_value, vmax=max_value)
plt.show()

这篇关于如何使用Mathplot IMShow显示一个白色像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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