In trying to manipulate a graph in matplotlib, I came across something interesting. when using the plot function, x and y coordinates can be modified through aliasing, however the z cannot. Is this easily explained?
I have included a small example, note that I was trying to get the point to move in a helix along the cylinder.
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
radius = 8
# Cylinder
x = np.linspace(-radius, radius, 100)
z = np.linspace(0, 2, 100)
X, Z = np.meshgrid(x, z)
Y = np.sqrt(radius**2 - X**2)
ax.plot_surface(X, Y, Z, alpha=0.3, linewidth=0)
ax.plot_surface(X, (-Y), Z,alpha=0.3, linewidth=0)
X = np.array(np.zeros(1))
Y = np.array(np.zeros(1))
Z = np.array(np.zeros(1))
X[0]= radius*np.cos(np.deg2rad(0))
Y[0]= radius*np.sin(np.deg2rad(0))
Z[0]= 0.
ax.plot(X,Y,Z, 'or',markersize=3)
for i in range(0,360,5):
X[0]= radius*np.cos(np.deg2rad(i))
Y[0]= radius*np.sin(np.deg2rad(i))
Z[0]= i/140.
plt.draw()
plt.pause(0.01)
For reference, the end goal of this exercise is to be able to position the point based on sensor inputs in real-time, in three dimensions.
Thank you to anyone who has insight as to why this is occurring and possible solutions!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…