from mpl_toolkits import mplot3d import matplotlib.pyplot as plt from mpl_toolkits.mplot3d.axes3d import Axes3D x = [0] y = [0] z = [0] plt.ion() # 开启一个画图的窗口 fig = plt.figure() while True: x.append(int(input("请输入x:"))) y.append(int(input("请输入y:"))) z.append(int(input("请输入z:"))) plt.cla() ax = fig.gca(projection='3d') ax.plot(x, y, z, 'gray') # plt.show() plt.pause(0.1) # 暂停一秒 plt.ioff() # 关闭画图的窗口
想实现根据输入重新绘制3维轨迹的功能,但是使用plt.cla()后,出现UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
ax = fig.gca(projection='3d').
第二次绘制,axes就变成二维的了。为什么?