plots.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. hdf_path = 'Data.h5'
  5. fixation_data = pd.read_hdf(hdf_path, 'fixation_data')
  6. fixslide_fixation_data = pd.read_hdf(hdf_path, 'fixslide_fixation_data')
  7. saccade_data = pd.read_hdf(hdf_path, 'saccade_data')
  8. fixslide_saccade_data = pd.read_hdf(hdf_path, 'fixslide_saccade_data')
  9. monkeys = ['Ned','Apu','Marge','Lenny','Walter']
  10. monkey_color_map=dict(zip(monkeys, 'gbcmk'))
  11. fixations = {
  12. 'front': fixation_data.reset_index().query('front and not scrambled'),
  13. 'side': fixation_data.reset_index().query('not front and not scrambled'),
  14. 'scrambled': fixation_data.reset_index().query('scrambled'),
  15. 'fix_slide': fixslide_fixation_data
  16. }
  17. saccades = {
  18. 'front': saccade_data.reset_index().query('front and not scrambled'),
  19. 'side': saccade_data.reset_index().query('not front and not scrambled'),
  20. 'scrambled': saccade_data.reset_index().query('scrambled'),
  21. 'fix_slide': fixslide_saccade_data
  22. }
  23. fig, axes = plt.subplots(4, 1, figsize=(3,7), sharex=True, sharey=True)
  24. conditions = ['fix_slide', 'scrambled', 'front', 'side']
  25. for condition, ax in zip(conditions, axes):
  26. for monkey, data in fixations[condition].groupby('monkey').duration:
  27. weights = np.ones_like(data) / data.size
  28. counts, bin_edges = np.histogram(data, bins=15, range=(0,600), weights=weights)
  29. x = np.mean([bin_edges[:-1], bin_edges[1:]], axis=0)
  30. ax.plot(x, counts, c=monkey_color_map[monkey], marker='o', markersize=2.5)
  31. ax.axvline(fixations[condition].groupby('monkey').duration.median().mean(), color='red')
  32. ax.set_title(condition)
  33. ax.set_ylabel('Proportion')
  34. ax.spines['right'].set_visible(False)
  35. ax.spines['top'].set_visible(False)
  36. fig.savefig(f'FixationDuration.png')
  37. fig, axes = plt.subplots(4, 1, figsize=(3,7), sharex=True, sharey=True)
  38. conditions = ['fix_slide', 'scrambled', 'front', 'side']
  39. for condition, ax in zip(conditions, axes):
  40. for monkey, data in saccades[condition].groupby('monkey').amplitude:
  41. weights = np.ones_like(data) / data.size
  42. counts, bin_edges = np.histogram(data, bins=8, range=(0,16), weights=weights)
  43. x = np.mean([bin_edges[:-1], bin_edges[1:]], axis=0)
  44. ax.plot(x, counts, c=monkey_color_map[monkey], marker='o', markersize=2.5)
  45. ax.axvline(saccades[condition].groupby('monkey').amplitude.median().mean(), color='red')
  46. ax.set_title(condition)
  47. ax.set_ylabel('Proportion')
  48. ax.spines['right'].set_visible(False)
  49. ax.spines['top'].set_visible(False)
  50. fig.savefig(f'SaccadeAmplitude.png')