TypeError: 'Line3DCollection' object is not iterable












1















I'm trying to create animation about how the value of a quantum bit would be changed by computation called X-gate, in form of an arrow.
Here are the codes that I wrote.



#Import libraries
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np

#Accept input (theta, phi) from a user
print("Put angle theta and phi, 0≤ theta ≤180, 0≤ phi ≤360")
theta = input("theta:")
phi = input("phi:")
theta = np.radians(float(theta))
phi = np.radians(float(phi))

#Calculate x,y,z coordinates
X = np.sin(theta) * np.cos(phi)
Y = np.sin(theta) * np.sin(phi)
Z = np.cos(theta)

#Adjusting the length of an arrow
length = np.sqrt(X**2 + Y**2 + Z**2)
if length > 1:
X = X/length
Y = Y/length
Z = Z/length

# Figure of the animation
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
x = np.cos(u)*np.sin(v)
y = np.sin(u)*np.sin(v)
z = np.cos(v)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.plot_wireframe(x,y,z, color="black")

# Calculate x,y,z coordinates in the process of the change
length = 9
xgate_theta = np.linspace(theta,theta+np.pi,length)
xgate_phi = np.linspace(phi,phi,length)

#Array of x,y,z coordinates
xgate=

# Only x coordinates
xgate_x =

# Only y coordinates
xgate_y =

# Only z coordinates
xgate_z =

for i in range(length):
xgate_x.append(X)
xgate_z.append(np.cos(xgate_theta[i]))
xgate_y.append(np.sqrt(1-np.sqrt(xgate_x[i]**2+xgate_z[i]**2))*(-1))
for j in range(length):
xgate.append(plt.quiver(0,0,0,xgate_x[j],xgate_y[j],xgate_z[j],color="red"))


ani = animation.ArtistAnimation(fig,xgate,interval=1000)
plt.show()


Then, I got the following error.



Traceback (most recent call last):
File "/Users/makotonakai/anaconda3/lib/python3.6/site- packages/matplotlib/cbook/__init__.py", line 388, in process
proxy(*args, **kwargs)
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/cbook/__init__.py", line 228, in __call__
return mtd(*args, **kwargs)
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 1026, in _start
self._init_draw()
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 1556, in _init_draw
for artist in f:
TypeError: 'Line3DCollection' object is not iterable


I cannot tell what line causes this error by just looking this error message. Can anybody tell me how I can fix this error?










share|improve this question























  • My best guess - which could be very wrong - is that it's complaining about the lines where you iterate (for j in range(length)): over the appending of plt.quiver as the error says that a Line3DCollection is not iterable, and this is the only place where you iterate over something like that.

    – heather
    Jan 21 at 12:55
















1















I'm trying to create animation about how the value of a quantum bit would be changed by computation called X-gate, in form of an arrow.
Here are the codes that I wrote.



#Import libraries
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np

#Accept input (theta, phi) from a user
print("Put angle theta and phi, 0≤ theta ≤180, 0≤ phi ≤360")
theta = input("theta:")
phi = input("phi:")
theta = np.radians(float(theta))
phi = np.radians(float(phi))

#Calculate x,y,z coordinates
X = np.sin(theta) * np.cos(phi)
Y = np.sin(theta) * np.sin(phi)
Z = np.cos(theta)

#Adjusting the length of an arrow
length = np.sqrt(X**2 + Y**2 + Z**2)
if length > 1:
X = X/length
Y = Y/length
Z = Z/length

# Figure of the animation
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
x = np.cos(u)*np.sin(v)
y = np.sin(u)*np.sin(v)
z = np.cos(v)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.plot_wireframe(x,y,z, color="black")

# Calculate x,y,z coordinates in the process of the change
length = 9
xgate_theta = np.linspace(theta,theta+np.pi,length)
xgate_phi = np.linspace(phi,phi,length)

#Array of x,y,z coordinates
xgate=

# Only x coordinates
xgate_x =

# Only y coordinates
xgate_y =

# Only z coordinates
xgate_z =

for i in range(length):
xgate_x.append(X)
xgate_z.append(np.cos(xgate_theta[i]))
xgate_y.append(np.sqrt(1-np.sqrt(xgate_x[i]**2+xgate_z[i]**2))*(-1))
for j in range(length):
xgate.append(plt.quiver(0,0,0,xgate_x[j],xgate_y[j],xgate_z[j],color="red"))


ani = animation.ArtistAnimation(fig,xgate,interval=1000)
plt.show()


Then, I got the following error.



Traceback (most recent call last):
File "/Users/makotonakai/anaconda3/lib/python3.6/site- packages/matplotlib/cbook/__init__.py", line 388, in process
proxy(*args, **kwargs)
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/cbook/__init__.py", line 228, in __call__
return mtd(*args, **kwargs)
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 1026, in _start
self._init_draw()
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 1556, in _init_draw
for artist in f:
TypeError: 'Line3DCollection' object is not iterable


I cannot tell what line causes this error by just looking this error message. Can anybody tell me how I can fix this error?










share|improve this question























  • My best guess - which could be very wrong - is that it's complaining about the lines where you iterate (for j in range(length)): over the appending of plt.quiver as the error says that a Line3DCollection is not iterable, and this is the only place where you iterate over something like that.

    – heather
    Jan 21 at 12:55














1












1








1








I'm trying to create animation about how the value of a quantum bit would be changed by computation called X-gate, in form of an arrow.
Here are the codes that I wrote.



#Import libraries
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np

#Accept input (theta, phi) from a user
print("Put angle theta and phi, 0≤ theta ≤180, 0≤ phi ≤360")
theta = input("theta:")
phi = input("phi:")
theta = np.radians(float(theta))
phi = np.radians(float(phi))

#Calculate x,y,z coordinates
X = np.sin(theta) * np.cos(phi)
Y = np.sin(theta) * np.sin(phi)
Z = np.cos(theta)

#Adjusting the length of an arrow
length = np.sqrt(X**2 + Y**2 + Z**2)
if length > 1:
X = X/length
Y = Y/length
Z = Z/length

# Figure of the animation
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
x = np.cos(u)*np.sin(v)
y = np.sin(u)*np.sin(v)
z = np.cos(v)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.plot_wireframe(x,y,z, color="black")

# Calculate x,y,z coordinates in the process of the change
length = 9
xgate_theta = np.linspace(theta,theta+np.pi,length)
xgate_phi = np.linspace(phi,phi,length)

#Array of x,y,z coordinates
xgate=

# Only x coordinates
xgate_x =

# Only y coordinates
xgate_y =

# Only z coordinates
xgate_z =

for i in range(length):
xgate_x.append(X)
xgate_z.append(np.cos(xgate_theta[i]))
xgate_y.append(np.sqrt(1-np.sqrt(xgate_x[i]**2+xgate_z[i]**2))*(-1))
for j in range(length):
xgate.append(plt.quiver(0,0,0,xgate_x[j],xgate_y[j],xgate_z[j],color="red"))


ani = animation.ArtistAnimation(fig,xgate,interval=1000)
plt.show()


Then, I got the following error.



Traceback (most recent call last):
File "/Users/makotonakai/anaconda3/lib/python3.6/site- packages/matplotlib/cbook/__init__.py", line 388, in process
proxy(*args, **kwargs)
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/cbook/__init__.py", line 228, in __call__
return mtd(*args, **kwargs)
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 1026, in _start
self._init_draw()
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 1556, in _init_draw
for artist in f:
TypeError: 'Line3DCollection' object is not iterable


I cannot tell what line causes this error by just looking this error message. Can anybody tell me how I can fix this error?










share|improve this question














I'm trying to create animation about how the value of a quantum bit would be changed by computation called X-gate, in form of an arrow.
Here are the codes that I wrote.



#Import libraries
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np

#Accept input (theta, phi) from a user
print("Put angle theta and phi, 0≤ theta ≤180, 0≤ phi ≤360")
theta = input("theta:")
phi = input("phi:")
theta = np.radians(float(theta))
phi = np.radians(float(phi))

#Calculate x,y,z coordinates
X = np.sin(theta) * np.cos(phi)
Y = np.sin(theta) * np.sin(phi)
Z = np.cos(theta)

#Adjusting the length of an arrow
length = np.sqrt(X**2 + Y**2 + Z**2)
if length > 1:
X = X/length
Y = Y/length
Z = Z/length

# Figure of the animation
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
x = np.cos(u)*np.sin(v)
y = np.sin(u)*np.sin(v)
z = np.cos(v)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.plot_wireframe(x,y,z, color="black")

# Calculate x,y,z coordinates in the process of the change
length = 9
xgate_theta = np.linspace(theta,theta+np.pi,length)
xgate_phi = np.linspace(phi,phi,length)

#Array of x,y,z coordinates
xgate=

# Only x coordinates
xgate_x =

# Only y coordinates
xgate_y =

# Only z coordinates
xgate_z =

for i in range(length):
xgate_x.append(X)
xgate_z.append(np.cos(xgate_theta[i]))
xgate_y.append(np.sqrt(1-np.sqrt(xgate_x[i]**2+xgate_z[i]**2))*(-1))
for j in range(length):
xgate.append(plt.quiver(0,0,0,xgate_x[j],xgate_y[j],xgate_z[j],color="red"))


ani = animation.ArtistAnimation(fig,xgate,interval=1000)
plt.show()


Then, I got the following error.



Traceback (most recent call last):
File "/Users/makotonakai/anaconda3/lib/python3.6/site- packages/matplotlib/cbook/__init__.py", line 388, in process
proxy(*args, **kwargs)
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/cbook/__init__.py", line 228, in __call__
return mtd(*args, **kwargs)
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 1026, in _start
self._init_draw()
File "/Users/makotonakai/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 1556, in _init_draw
for artist in f:
TypeError: 'Line3DCollection' object is not iterable


I cannot tell what line causes this error by just looking this error message. Can anybody tell me how I can fix this error?







python-3.x animation quantum-computing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 14:55









Makoto NakaiMakoto Nakai

266




266













  • My best guess - which could be very wrong - is that it's complaining about the lines where you iterate (for j in range(length)): over the appending of plt.quiver as the error says that a Line3DCollection is not iterable, and this is the only place where you iterate over something like that.

    – heather
    Jan 21 at 12:55



















  • My best guess - which could be very wrong - is that it's complaining about the lines where you iterate (for j in range(length)): over the appending of plt.quiver as the error says that a Line3DCollection is not iterable, and this is the only place where you iterate over something like that.

    – heather
    Jan 21 at 12:55

















My best guess - which could be very wrong - is that it's complaining about the lines where you iterate (for j in range(length)): over the appending of plt.quiver as the error says that a Line3DCollection is not iterable, and this is the only place where you iterate over something like that.

– heather
Jan 21 at 12:55





My best guess - which could be very wrong - is that it's complaining about the lines where you iterate (for j in range(length)): over the appending of plt.quiver as the error says that a Line3DCollection is not iterable, and this is the only place where you iterate over something like that.

– heather
Jan 21 at 12:55












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414750%2ftypeerror-line3dcollection-object-is-not-iterable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414750%2ftypeerror-line3dcollection-object-is-not-iterable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?