根据三维坐标可视化,每个坐标对应的数值
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation
x = np.arange(0,10,0.5)
y = np.arange(0,10,0.5)
z = np.arange(0,10,0.5)
x,y,z = np.meshgrid(x,y,z)
color = np.array([i+j+k for i,j,k in zip(x,y,z)])
print(color*10)
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(x,y,z,c=color)
# plt.savefig('1.png',dpi=100)
#旋转三维图并且保存成gif格式
def update(i):
label = 'timestep {0}'.format(i)
# 更新直线和x轴(用一个新的x轴的标签)。
# 用元组(Tuple)的形式返回在这一帧要被重新绘图的物体
horiAngle = (45 + 3 * i)%360#transition(i, 40)
vertAngle = (45 + 3 * i)%360#transition(i, 40)
print(label,horiAngle,vertAngle)
ax.view_init(vertAngle, horiAngle)
filename = str('%03d' % i) + '.png'
plt.savefig(filename, dpi=96)
return ax
anim = FuncAnimation(fig, update, frames=np.arange(0, 120), interval=200)
anim.save('line.gif', dpi=120, writer='imagemagick')