3

I've been trying to represent this structured array in a 3d plot in hopes of later mapping it.

import matplotlib.pyplot as plt
import numpy as np
import os
from mpl_toolkits.mplot3d import Axes3D

path = '/users/username/Desktop/untitled folder/python files/MSII_phasespace/'

os.chdir( path )

fig = plt.figure()
ax = fig.gca( projection='3d')


data = np.load('msii_phasespace.npy',mmap_mode='r')

# data.size: 167197
# data.shape: (167197,)
# data.dtype: dtype([('x', '<f4'), ('y', '<f4'), ('z', '<f4'),
  # ('velx', '<f4'), ('vely', '<f4'), ('velz', '<f4'), ('m200', '<f4')])



u = data[:500]
v = data[:500]

xi = u['x']
yi = v['y']


X, Y = np.meshgrid(xi, yi)
Axes3D.plot_surface(X, Y, data)


plt.show()

Running this led me to this error

unbound method plot_surface() must be called with Axes3D instance as first argument (got memmap instance instead).

I'm not entirely sure what it is asking me. I'm i bit of a beginner with this, so I would appreciate any help i can get. Also, would including a third value of z be applicable?

I've also included the size, shape, and dtype in #.

iron2man
  • 1,787
  • 5
  • 27
  • 39

1 Answers1

1

The call to plot_surface must be made on a specific instance of Axes3D, not on the class. Python instance methods implicitly have a first self parameter that is passed in when you call a method on an object.

What this means for you is that Axes3D.plot_surface(X, Y, data) should be ax.plot_surface(X, Y, data). The ax object tells Python which set of axes to invoke plot_surface() on.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
  • I see, thank you. Unfortunately, trying that leads me this error `ValueError: shape mismatch: two or more arrays have incompatible dimensions on axis 1`. Can this be resolved by reshaping Y to `.Xsize`? Or would it be better to post this new found error as a entirely different question? – iron2man Nov 30 '15 at 17:39
  • plot `X`, `Y`, `data[:500]` instead of just `data` since it has to be the same size as the x and y coordinates. – Mad Physicist Nov 30 '15 at 17:43
  • Awesome. Thank you again. – iron2man Nov 30 '15 at 17:49
  • mea culpa, there you go. – iron2man Nov 30 '15 at 18:27