
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, FancyArrowPatch
from matplotlib.animation import FuncAnimation
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 6))
ax1.set_aspect('equal')
ax2.set_aspect('auto')
ax1.set_xlim(-2, 2)
ax1.set_ylim(-2, 2)
ax2.set_xlim(0, 2 * np.pi)
ax2.set_ylim(-1.5, 1.5)
ax1.set_xlabel('X axis')
ax1.set_ylabel('Y axis')
ax2.set_xlabel('Angle (radians)')
ax2.set_ylabel('Amplitude')
ax1.set_title('Rotating Arrows')
ax2.set_title('Sine Waves')
inner_circle = Circle((0, 0), 1, color='blue', fill=False)
outer_circle = Circle((0, 0), 1.5, color='black', fill=False)
ax1.add_patch(inner_circle)
ax1.add_patch(outer_circle)
short_arrow_scale = 1
long_arrow_scale = 1.5
arrow1 = FancyArrowPatch((0, 0), (short_arrow_scale, 0), color='red', mutation_scale=10, arrowstyle='->', lw=2)
arrow2 = FancyArrowPatch((0, 0), (short_arrow_scale, 0), color='green', mutation_scale=10, arrowstyle='->', lw=2)
arrow3 = FancyArrowPatch((0, 0), (short_arrow_scale, 0), color='blue', mutation_scale=10, arrowstyle='->', lw=2)
long_arrow = FancyArrowPatch((0, 0), (long_arrow_scale, 0), color='purple', mutation_scale=15, arrowstyle='->', lw=2)
ax1.add_patch(arrow1)
ax1.add_patch(arrow2)
ax1.add_patch(arrow3)
ax1.add_patch(long_arrow)
x_data = np.linspace(0, 2 * np.pi, 1000)
line1, = ax2.plot(x_data, np.sin(x_data), 'r-', label='sin(ωt)')
line2, = ax2.plot(x_data, np.sin(x_data + 2 * np.pi / 3), 'g-', label='sin(ωt + 2π/3)')
line3, = ax2.plot(x_data, np.sin(x_data + 4 * np.pi / 3), 'b-', label='sin(ωt + 4π/3)')
ax2.legend()
angle = 0
def update(frame):
global angle
angle += 0.05
if angle > 2 * np.pi:
angle = 0
arrow1.set_positions((0, 0), (short_arrow_scale * np.cos(angle), short_arrow_scale * np.sin(angle)))
arrow2.set_positions((0, 0), (short_arrow_scale * np.cos(angle + 2 * np.pi / 3), short_arrow_scale * np.sin(angle + 2 * np.pi / 3)))
arrow3.set_positions((0, 0), (short_arrow_scale * np.cos(angle + 4 * np.pi / 3), short_arrow_scale * np.sin(angle + 4 * np.pi / 3)))
long_arrow.set_positions((0, 0), (long_arrow_scale * np.cos(angle + np.pi / 6), long_arrow_scale * np.sin(angle + np.pi / 6)))
line1.set_ydata(np.sin(x_data + angle))
line2.set_ydata(np.sin(x_data + angle + 2 * np.pi / 3))
line3.set_ydata(np.sin(x_data + angle + 4 * np.pi / 3))
return arrow1, arrow2, arrow3, long_arrow, line1, line2, line3
ani = FuncAnimation(fig, update, frames=np.arange(0, 360), interval=50, blit=True, repeat=True)
ani.save('sine_waves_and_arrows.gif', writer='pillow', fps=12)
plt.show()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2020-11-10 计算机问题排查记录