fork download
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. # 设置画布
  5. fig, ax = plt.subplots(figsize=(6, 6))
  6. ax.set_aspect('equal')
  7.  
  8. # 生成爱心形状的数据
  9. t = np.linspace(0, 2*np.pi, 1000)
  10. x = 16 * np.sin(t) ** 3
  11. y = 13 * np.cos(t) - 5 * np.cos(2*t) - 2 * np.cos(3*t) - np.cos(4*t)
  12.  
  13. # 绘制爱心
  14. ax.fill(x, y, 'red', alpha=0.8)
  15.  
  16. # 设置标题和坐标轴
  17. ax.set_title('Python爱心', fontsize=15)
  18. ax.set_xlim(-20, 20)
  19. ax.set_ylim(-20, 15)
  20. ax.axis('off') # 隐藏坐标轴
  21.  
  22. # 显示图形
  23. plt.show()
Success #stdin #stdout #stderr 3.51s 68504KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Fontconfig error: No writable cache directories