Advertisement
rodrigosantosbr

Positions of Particles in a 3-Particle System in Matplotlib

Mar 27th, 2024
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2.  
  3. # Particles data: mass and positions
  4. particles = {
  5.     '5kg': {'mass': 5, 'position': (0, 0)},
  6.     '4kg': {'mass': 4, 'position': (1, 2)},
  7.     '3kg': {'mass': 3, 'position': (2, 0)}
  8. }
  9. # Plotting the particle positions
  10. plt.figure(figsize=(8, 6))
  11. for label, p in particles.items():
  12.     plt.plot(p['position'][0], p['position'][1], 'o', label=f"{label} at {p['position']}")
  13. plt.title('Positions of Particles in a 3-Particle System')
  14. plt.xlabel('x [m]’); plt.ylabel('y [m]); plt.grid(True)
  15. plt.axhline(0, color='black', linewidth=0.5)
  16. plt.axvline(0, color='black', linewidth=0.5)
  17. plt.legend()
  18. plt.axis('equal')
  19. plt.show()
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement