Thanks for the responses.
I got it working with floats but maybe you all can tell me why. I just created an account here and can't edit my guest question...
I'm getting my data from a sqlite database. I can round the values in the sql or cast to floats and it works. I'm guessing that the data was a numerical object even though it was numerical. Is this correct?
Here's an excerpt of the code that doesn't work. I got it to work by casting the values as floats.
import sqlite3
import re
import numpy as np
from numpy import *
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
conn = sqlite3.connect('./RES/resDB.dbl')
fig = plt.figure()
ax = Axes3D(fig)
sam = array([])
x = array([])
y = array([])
z = array([])
for sv in conn.execute('select sam,easting,northing,altitude from trx_all'):
sam = np.append(sam, [sv[0]]) #this works: sam = np.append(sam, [float(sv[0])])
x = np.append(x, [sv[1]]) #this works: x = np.append(x, [float(sv[1])])
y = np.append(y, [sv[2]]) #this works: y = np.append(y, [float(sv[2])])
z = np.append(z, [sv[3]]) #this works: z = np.append(z, [float(sv[3])])
if sam.__len__() > 0:
print(repr(x))
print(repr(y))
print(repr(z))
ax.scatter(x, y, z, marker='o')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title("3D plot")
plt.show()
unutbu requested the output of print(repr(x)):
x: array([u'227004.744896075', u'227029.694213685', u'227051.351657645', ...,
u'226416.484484696', u'226436.436477995', u'226401.253669657'],
dtype='U16')
y: array([u'3648736.75423911', u'3648737.3357031', u'3648746.34280013', ...,
u'3645870.67565062', u'3645893.61216942', u'3645866.95833722'],
dtype='U16')
z: array([u'1600.2589433603', u'1535.77224937826', u'1429.01016684435', ...,
u'341.064685015939', u'343.452275622636', u'312.491347198375'],
dtype='U16')
and finally here's the error that it outputs on the line ax.scatter(x,y,z,marker='o') :
Traceback (most recent call last):
File "C:\stripped_3dplot.py", line 27, in
ax.scatter(x, y, z, marker='o')
File "C:\Python27\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 1019, in scatter
patches = Axes.scatter(self, xs, ys, *args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 5813, in scatter
minx = np.amin(temp_x)
File "C:\Python27\lib\site-packages\numpy\core\fromnumeric.py", line 1846, in amin
return amin(axis, out)
TypeError: cannot perform reduce with flexible type
Like i said i think it was just the wrong type, but if you all can tell me what type causes the error i could learn something.
Thanks.