orbitalDecay.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """Plot the trajectories followed by the central masses
  2. to illustrate orbital decay due to dark matter halos"""
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. from analysis import utils
  6. def plotTrajectory(data, ax, axisOn, trajectory):
  7. """Plot the trajectory followed by the central masses
  8. Parameters:
  9. ax: the matplotlib axis where the data should be plotted
  10. data: a data dictionary in the format saved by the simulation
  11. axisOn (bool): whether to include the y axis in this subplot.
  12. It can be omitted when it is shared among subplots.
  13. trajectory (string): type of theoretical trajectory
  14. ('ellipse' or 'hyperbola') to superpose
  15. """
  16. # Plot trajectory
  17. ax.plot(np.array(data['tracks'])[0,:,0], np.array(data['tracks'])[0,:,1],
  18. c='black', alpha=1.0, linewidth=1)
  19. ax.plot(np.array(data['tracks'])[1,:,0], np.array(data['tracks'])[1,:,1],
  20. c='black', alpha=0.6, linewidth=1)
  21. ax.axis('square')
  22. # Superpose theoretical trajectory
  23. if trajectory=='ellipse':
  24. traj = patches.Arc((-.5,0), width=2, height=np.sqrt(3),
  25. theta1=-180, theta2=100, linewidth=2, edgecolor='black',
  26. facecolor='none', alpha=.7, linestyle='dashed')
  27. ax.add_patch(traj)
  28. utils.setSize(ax, x=(-1.5, 1.5), y=(-1.5, 1.5))
  29. elif trajectory=='ellipse': #x = 1/2 - y^2/2
  30. y = np.linspace(-2.5, 3, 1000)
  31. x = 1/2 - y**2/2
  32. ax.plot(x, y, linewidth=2, color='black',
  33. alpha=.7, linestyle='dashed')
  34. utils.setSize(ax, x=(-1.5, 1.5), y=(-1.5, 1.5))
  35. else: raise Exception('Unknown trajectory')
  36. # Styling
  37. utils.setAxes(ax, x=r'x\' / $r_{min}$', y=r'y\' / $r_{min}$',
  38. ycoords=(-0.2, .8), mode=('bottomleft' if axisOn else 'bottom'))
  39. utils.stylizePlot([ax])
  40. f, axs = plt.subplots(1, 4, figsize=(15, 4), sharey=False, sharex=False)
  41. # Plot the four encounters described in the report
  42. data = utils.loadData('elliptical_nohalo', 30000)
  43. plotTrajectory(data, ax=axs[0], axisOn=True, trajectory='ellipse')
  44. data = utils.loadData('elliptical_halo', 30000)
  45. plotTrajectory(data, ax=axs[1], axisOn=True, trajectory='ellipse')
  46. data = utils.loadData('hyperbolic_nohalo', 50000)
  47. plotTrajectory(data, ax=axs[2], axisOn=True, trajectory='ellipse')
  48. data = utils.loadData('hyperbolic_halo', 100000)
  49. plotTrajectory(data, ax=axs[3], axisOn=True, trajectory='ellipse')
  50. f.subplots_adjust(hspace=0, wspace=0)
  51. plt.tight_layout()
  52. plt.show()