Value error: Argument Z must be 2-dimensional

Joined
Mar 26, 2022
Messages
2
Reaction score
0
Im getting the error "Value error: Argument Z must be 2-dimensional" for the following code. Its purpose is to move a sphere around according to coordinate values I have in a text file:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
from matplotlib import cm
from matplotlib import animation
import pandas as pd

df = pd.read_csv('/users/thomm/Downloads/2S_2MIL.txt', sep=" ", header=None)

fig = plt.figure(facecolor='black')
ax = plt.axes(projection = "3d")

u = np.linspace(0, 2*np.pi, 100)
v = np.linspace(0, np.pi, 100)
r = 4

ax.set_xlim(0, 60)
ax.set_ylim(0, 60)
ax.set_zlim(0, 60)

x0 = r * np.outer(np.cos(u), np.sin(v)) + df[1][0]
y0 = r * np.outer(np.sin(u), np.sin(v)) + df[2][0]
z0 = r * np.outer(np.ones(np.size(u)), np.cos(v)) + df[3][0]

surface_color = "tab:blue"

def init():
ax.plot_surface(x0, y0, z0, color=surface_color)
return fig,

def animate(i):
# remove previous collections
ax.collections.clear()
x = df[1]
y = df[2]
z = df[3]
# add the new sphere
ax.plot_surface(x, y, z, color=surface_color)
return fig,

ani = animation. FuncAnimation(fig, animate, init_func = init, frames = 500, interval = 2)
plt.show()

Any help would be appreciated, thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,818
Messages
2,569,727
Members
45,661
Latest member
NadineBour

Latest Threads

Top