-1

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

3
  • Down votes without comment are not very useful. Commented May 16, 2016 at 16:49
  • You state what you don't want, but not what you actually do want. Commented May 16, 2016 at 17:44
  • @Han-KwangNienhuys I guess my first paragraph is not clear. I have a 2d array, I want to visualize it in 3d, with the z axis representing the value of the array at each point. I want to be able to rotate it using mouse drags. Commented May 16, 2016 at 18:20

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.