Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I want to plot a point with an array using matplotlib, but it fails to read the array for data.

A test case is provided here, where if I use plt.plot([1], [1], [1], 'or') it works, but if I use plt.plot(Point[0], Point[1], Point[2], 'or') it fails generating the error:

TypeError: object of type 'numpy.int32' has no len()

Any suggestions?

Thanks for the help!

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from scipy.spatial import ConvexHull
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')

ax.set_xlim3d(0,3)
ax.set_ylim3d(0,3)
ax.set_zlim3d(0,3)

Point = np.array([1,1,1])
plt.plot([1], [1], [1], 'or')
plt.plot(Point[0], Point[1], Point[2], 'or')

plt.show()
share|improve this question
1  
It fails because .plot() expects a sequence of points, and Point[0] is not a sequence. – cel Nov 13 at 15:04
1  
Please provide the exact error that it raises. – Sque Nov 13 at 15:04
    
Can you suggest me a way to use the data I put in Point in order for it to work? Sorry if it may be too easy, but I am really new in Python – TM. Nov 13 at 15:07

1 Answer 1

up vote 0 down vote accepted

as @cel told in the comments plot expects sequence of points. Try this for instance:

plt.plot([[1]], [[1]], [[1]], 'or')
plt.plot([Point[0]], [Point[1]], [Point[2]], 'or')
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.