"Fast" interactive plot of a 2d numpy array in python
Question: I have a need to visualize a 2d numpy array in python. Not a contour plot, not
a surface plot. Plot a point on a z axis for every (x,y) element in the 3d
array. My data is a 1024 x 1024 array, but I suppose I could decimate it if I
had to. I need to be able to rotate the plot with mouse drags to see it from
different perspectives.

Matplotlib cannot do this, even for a 100 x 100 array. It is much much too
slow. A 100 x 100 array takes two or three seconds to redraw after dragging.
1024 x 1024 is out of the question.

mlab from Mayavi seems to have this capability, but the simplest trial crashes
on my system with wx errors. As far as I can tell, packages that provide fast
interactive rotation (e.g. VTK) are focused on rendering complex 3d shapes,
and don't provide a simple API for plotting data.

Can you suggest options?

My current setup:  
OS X 10.11.4  
python 1.7.11  
numpy 1.11.0  
matplotlib 1.5.1  
mayavi 4.4.0  
wx 3.0.0.0


Answer: This is an xyz plot with 20x20 decimation, which is about the highest that my
laptop will comfortably do. More points than this doesn't make much sense
anyway, since you wouldn't be able to tell the individual points apart
anymore.

    
    
    from mpl_toolkits.mplot3d.axes3d import Axes3D
    import matplotlib.pyplot as plt
    import numpy as np
    
    fig = plt.figure()
    X = np.linspace(-3,3,1024)
    Y = np.linspace(-3,3,1024)
    X, Y = np.meshgrid(X, Y)
    Z = np.exp(-(X**2+Y**2))
    ax = fig.add_subplot(1, 1, 1, projection='3d')
    ax.plot_wireframe(X, Y, Z, rstride=20, cstride=20)
    
    plt.show(block=False)
    raw_input('Press ENTER')
    

You could consider plotting via Gnuplot. It will handle interactive rotation
much faster than matplotlib. Example:

    
    
    set isosamp 50
    set xrange [-3:3]
    set yrange [-3:3]
    splot exp(-x**2-y**2)
    

There is a python module `Gnuplot.py` which should allow you to use it
directly from python.

