如何用Python在循环中显示单个色条?

2024-04-26 14:04:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试用matplotlib和Python3在一个循环中绘制加载的2D数据(512x512像素)的图像。但它显示的是带有多个色条的奇怪图像。这是我的密码:

import numpy as np
import sys
import os
from load_images import load, File
import matplotlib.pyplot as plt
from matplotlib import cm

arr_spe = [x for x in os.listdir() if x.endswith(".SPE")]

for x in arr_spe:
    try:
        dat = load(x)

        plt.imshow(dat,cmap=cm.jet, vmax = 2000)
        plt.colorbar()
        plt.savefig(x[:-4]+'.png', dpi=500, bbox_inches='tight')
    except ValueError as error: 
        print('ValueError(empty)-'+x) 

我使用代码在以下链接中加载数据:Reading SPE file from CCD camera,方法是将代码命名为load_图片.py. 你知道吗

我有很多像这样的照片 Results after running this code

有人有办法解决这个问题吗?只需在图像中显示单个色条


Tags: 数据infrom图像importformatplotlibos