首页 > 解决方案 > 如何让 PyDev 与 MathPlotLib 一起工作?

问题描述

每当我运行此代码时,都会弹出一个窗口并立即消失。Python 解释器已设置好,所有其他命令都可以在控制台和编辑器中运行。我目前正在使用 Eclipse 2019 和 Python 2.7。

将我的代码的最后一行从 fig.show() 更改为 PLT.show() 仅适用于这个程序(我需要一个更强大的解决方案)。为了以防万一,我已将 PyQt4 库安装到 Eclipse/PyDev 中。

'''
Read and show an image.
'''
import PIL
import matplotlib.pyplot as plt
import os.path
import numpy as np # "as" lets us use standard abbreviations
#from PyQt4.Qt import QEventLoop

'''Read the image data'''
# Get the directory of this python script
directory = os.path.dirname(os.path.abspath(__file__)) 
# Build an absolute filename from directory + filename
filename = os.path.join(directory, 'woman.jpg')
# Read the image data into an array
img = plt.imread(filename)

'''Show the image data'''
# Create figure with 1 subplot
fig, ax = plt.subplots(1, 1)
# Show the image data in a subplot
ax.imshow(img, interpolation='none')

# Show the figure on the screen
fig.show() #changed from fig.show()

没有错误消息,但窗口停留的时间不够长。

标签: eclipsepython-2.7matplotlibpydev

解决方案


推荐阅读