根据您的需要,matplotlib's imshow 或 glumpy 可能是最佳选择。
Matplotlib 更加灵活,但速度较慢(即使您做对了所有事情,matplotlib 中的动画也可能非常耗费资源。)。但是,您将拥有一个非常棒的功能齐全的绘图库。
Glumpy 非常适合快速、基于 openGL 的 2D numpy 数组的显示和动画,但它的功能更加有限。不过,如果您需要为一系列图像制作动画或实时显示数据,那么它是比 matplotlib 更好的选择。
使用 matplotlib(使用 pyplot API 代替 pylab):
import matplotlib.pyplot as plt
import numpy as np
# Generate some data...
x, y = np.meshgrid(np.linspace(-2,2,200), np.linspace(-2,2,200))
x, y = x - x.mean(), y - y.mean()
z = x * np.exp(-x**2 - y**2)
# Plot the grid
plt.imshow(z)
plt.gray()
plt.show()
使用 glumpy:
import glumpy
import numpy as np
# Generate some data...
x, y = np.meshgrid(np.linspace(-2,2,200), np.linspace(-2,2,200))
x, y = x - x.mean(), y - y.mean()
z = x * np.exp(-x**2 - y**2)
window = glumpy.Window(512, 512)
im = glumpy.Image(z.astype(np.float32), cmap=glumpy.colormap.Grey)
@window.event
def on_draw():
im.blit(0, 0, window.width, window.height)
window.mainloop()