ringPlot.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """Make a plot of an encountering with rings (fig 1, fig 3) and
  2. colour each ring according to the initial distance. It plots a
  3. prograde equalmass encounter by default.
  4. """
  5. import matplotlib.pyplot as plt
  6. from scipy.interpolate import splprep, splev, interp1d
  7. from matplotlib import markers
  8. import numpy as np
  9. from analysis.colormaps import parula_map
  10. from analysis import utils
  11. def plotRings(ax, data, n):
  12. """Make a ring plot of the data.
  13. Parameters:
  14. ax: the matplotlib axis where the data should be plotted
  15. data: a data dictionary in the format saved by the simulation
  16. n (int): the number of particles to plot. These will be interpolated
  17. and can be much higher than those originally in the simulation.
  18. """
  19. # Identify all the rings
  20. rings = np.unique(data['type'][:,1])
  21. rings = rings[rings!='0']
  22. # Plot each ring
  23. for ring, color, in zip(rings,
  24. parula_map(np.linspace(1.0, 0., len(rings)))):
  25. xy = data['r_vec'][data['type'][:,1]==ring] #data for this ring
  26. # Interpolate data (to use opacity to plot local density)
  27. tck, u = splprep(xy[:,:2].T, u=None, s=0.0, per=1)
  28. f = interp1d(np.linspace(0,1,len(u)), u, kind='cubic')
  29. x_new, y_new = splev(f(np.linspace(0,1,n)), tck, der=0)
  30. #Plot data
  31. ax.scatter(x_new, y_new, s=2, c=[color], alpha=0.01)
  32. utils.plotCOM(ax)
  33. utils.plotCenterMasses(ax, data)
  34. utils.plotTracks(ax, data['tracks'])
  35. # Styling
  36. utils.setAxes(ax, mode='hide')
  37. ####################################
  38. ####################################
  39. # List of times to plot
  40. ts = [2000, 3000, 3500, 4000, 4900]
  41. figsize = (12, 4)
  42. fileName = 'prograde_equalmass'
  43. f, axs = plt.subplots(1, len(ts), figsize=figsize, sharey=False)
  44. for t, ax in zip(ts, axs):
  45. data = utils.loadData(fileName, t)
  46. plotRings(ax, data, n=10000)
  47. height, width = 3.0, 3 * 1/len(ts) * figsize[0]/figsize[1]
  48. utils.setSize(ax, x=(-width, width), y=(-height, height), mode='square')
  49. f.subplots_adjust(hspace=0, wspace=0)
  50. plt.show()