1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation
plt.rcParams["font.sans-serif"] = ["SimHei"] plt.rcParams["axes.unicode_minus"] = False
xx = np.array([13, 5, 25, 13, 9, 19, 3, 39, 13, 27]) yy = np.array([4, 38, 16, 26, 7, 19, 28, 10, 17, 18]) zz = np.array([7, 19, 6, 12, 25, 19, 23, 25, 10, 15]) fig = plt.figure() ax = fig.add_subplot(111, projection='3d')
star = ax.scatter(xx, yy, zz, c='#C71585', marker='*', s=160, linewidth=1, edgecolor='black')
def animate(i): if i % 2: color = '#C71585' else: color = 'white' next_star = ax.scatter(xx, yy, zz, c=color, marker='*', s=160, linewidth=1, edgecolor='black') return next_star
def init(): return star
ani = FuncAnimation(fig=fig, func=animate, frames=None, init_func=init, interval=1000, blit=False)
ax.set_xlabel('x轴') ax.set_ylabel('y轴') ax.set_zlabel('z轴') ax.set_title('3D散点图', fontproperties='simhei', fontsize=14)
plt.tight_layout() plt.show()
|