Python's `imshow` hangs when I evaluate in con

2019-08-05 16:00发布

问题:

I am using PyCharm, on MacOS, and using Python 2.7.6.

The Problem: If I run my program, the image displays just fine. If however, I evaluate the code on the console, a figure appears, but just sits there without anything displayed, and just gives me the spinning beach ball. Why is this occurring? Here is the code:

import numpy as np
import matplotlib.pyplot as pl

fileName = '/data_batch_1'

def unpickle(file):
    import pickle
    fo = open(file, 'rb')
    dict = pickle.load(fo)
    fo.close()
    return dict

dict = unpickle(fileName)
data = dict['data']
labels = dict['labels']

imageIndex = 0
image = data[imageIndex,:]
imageVol = np.zeros((32,32,3), 'uint8')
for ii in range(0,3,1):
    imageVol[:,:,ii] = image[(ii*1024) : (ii+1)*1024].reshape([32, 32])
pl.imshow(imageVol,interpolation='none')
pl.show()