在此动画中,轴未出现,我看不到代码中缺少任何东西。我不知道动画是否那样做。我尝试了两种方法而没有解决方案。那么如何显示轴呢?
感谢您的帮助。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
n_drops = 100
rain_drops = np.zeros(n_drops, dtype=[('position', float, 2),
('size', float, 1),
('growth', float, 1),
('color', float, 4)])
scat = ax.scatter(rain_drops['position'][:, 0], rain_drops['position'][:, 1], s=rain_drops['size'], lw=0.5, edgecolors=rain_drops['color'], facecolors='midnightblue',marker='s')
def update(frame_number):
current_index = frame_number % n_drops
rain_drops['size'] += rain_drops['growth']
rain_drops['position'][current_index] = np.random.uniform(0, 0, 1)
rain_drops['size'][current_index] = 5
rain_drops['color'][current_index] = (0.05, 0.05, 0.09, 1)
rain_drops['growth'][current_index] = 200 #np.random.uniform(50, 200)
scat.set_edgecolors(rain_drops['color'])
scat.set_sizes(rain_drops['size'])
scat.set_offsets(rain_drops['position'])
animation = FuncAnimation(fig, update, interval=10)
plt.show()