Display array as raster image in python -


i've got numpy array in python , i'd display on-screen raster image. simplest way this? doesn't need particularly fancy or have nice interface, need display contents of array greyscale raster image.

i'm trying transition of idl code python numpy , looking replacement tv , tvscl commands in idl.

depending on needs, either matplotlib's imshow or glumpy best options.

matplotlib infinitely more flexible, slower (animations in matplotlib can suprisingly resource intensive when right.). however, you'll have wonderful, full-featured plotting library @ disposal.

glumpy suited quick, opengl based display , animation of 2d numpy array, more limited in does. if need animate series of images or display data in realtime, it's far better option matplotlib, though.

using matplotlib (using pyplot api instead of pylab):

import matplotlib.pyplot plt import numpy np  # generate 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 grid plt.imshow(z) plt.gray() plt.show() 

using glumpy:

import glumpy import numpy np  # generate 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() 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -