python - 为什么 pyplot imshow 与其颜色条不匹配?
问题描述
问题是:如何用相同的黑色表示不同的值(0 和 255)?并且相同的值(255)也以黑白显示?
我的代码如下:
#Vizualizing grayscale
def visualize_input(img,ax):
pos=ax.imshow(img,cmap='gray')
width,height=img.shape
#thresh = img.max()
for x in range (width):
for y in range(height):
ax.annotate(str(round(img[x][y],2)), xy=(x,y),
horizontalalignment='center',
verticalalignment='center',
color='blue') #if img[x][y]<=thresh else 'black')
plt.colorbar(pos)
fig=plt.figure(figsize=(15,15))
ax=fig.add_subplot()
visualize_input(X_train[0].reshape(28,28),ax)
任何有用的帮助!
解决方案
The problem was that due to FOR order i had to set xy=(y,x).
推荐阅读
- r - 无法使用 Rscript.exe 调用“excel.link”包
- string - 如何为新的 Azure API 管理开发门户添加字符串资源和切换语言
- python - TensorFlow 模型教程脚本升级到 v2
- jquery - scrollTop 滚动到适当的位置然后回到顶部
- python - 虽然循环不会无限期运行[python3]?
- java - Eclipse 拒绝启动搜索算法
- php - php。从结果表构建多维数组
- r - 无法使用 dplyr 重命名列
- python - 散景 - 如何将 y 值添加到水平 Span 的 y 轴?
- ruby-on-rails - 为什么我自己的域不会显示我的页面,但 heoku 网站会?