figS4.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # code to plot Fig. S4
  2. # import
  3. import matplotlib.pyplot as plt
  4. import scipy.io
  5. import numpy as np
  6. import spatint_utils
  7. import os
  8. # load plot params
  9. spatint_utils.plot_params()
  10. class FigS4:
  11. """Class for plotting Fig. S4"""
  12. def __init__(self):
  13. """Init class"""
  14. parentdir = os. path. dirname(os. getcwd())
  15. # load data from matfile
  16. data = scipy.io.loadmat(parentdir + '/data/v1_spat_int.mat')
  17. # unfold data
  18. self.layerDepth = data['layerDepth'][0]
  19. self.center_sz_c_smooth = np.array([x[0] for x in data['center_sz_c_smooth']])
  20. self.si_c_smooth = np.array([x[0] for x in data['si_c_smooth']])
  21. self.layerY = data['layerY'][0]
  22. self.max_sz_plot = data['max_sz_plot'][0][0]
  23. self.rel_layerDepth = data['rel_layerDepth'][0]
  24. self.si_c = data['si_c'][0]
  25. self.relative_depth = data['relative_depth'][0]
  26. self.center_sz_c = data['center_sz_c'][0]
  27. def rfcs_x_depth(self, ax=None, figsize=(2.5, 2.5)):
  28. """Plot preferred size against cortical depth in V1 (Fig. S4a)
  29. Parameters
  30. -------
  31. figsize: tuple
  32. Figure size (width, height)
  33. ax: mpl axis
  34. axis for plot
  35. Returns
  36. -------
  37. ax: mpl axis
  38. axis for plot
  39. """
  40. if ax is None:
  41. # init figure
  42. f, ax = plt.subplots(figsize=figsize)
  43. # plot
  44. self.center_sz_c[self.center_sz_c > self.max_sz_plot] = self.max_sz_plot + 20
  45. ax.scatter(self.center_sz_c, self.relative_depth, color='k', facecolor='none')
  46. ax.plot(self.center_sz_c_smooth, self.relative_depth, color='r')
  47. for layer in self.layerY:
  48. ax.hlines(layer, 0, self.max_sz_plot, color='k', linestyle='--')
  49. # layout
  50. ax.set_xlabel('Preferred size ($\degree$)')
  51. ax.set_ylabel('Cortical depth to\nbase of L4 (mm)')
  52. ax.set_xlim(-2, self.max_sz_plot+25)
  53. ax.set_ylim([(self.rel_layerDepth[0] - self.layerDepth[0]) / 1000, self.rel_layerDepth[
  54. -1] / 1000])
  55. ax.invert_yaxis()
  56. ax.set_yticks(())
  57. ax.set_xticks((0, 25, 50, 75, 95))
  58. ax.set_xticklabels((0, 25, 50, 75, '>75'))
  59. ax.set_yticks((-0.4, 0, 0.4))
  60. ax.set_yticklabels(())
  61. ax.spines['bottom'].set_bounds(0, self.max_sz_plot)
  62. f = plt.gcf()
  63. f.tight_layout()
  64. # print n
  65. print('n = %d' % len(self.relative_depth))
  66. return ax
  67. def si_x_depth(self, ax=None, figsize=(2.5, 2.5)):
  68. """Plot suppression index against cortical depth in V1 (Fig. S4b)
  69. Parameters
  70. -------
  71. figsize: tuple
  72. Figure size (width, height)
  73. ax: mpl axis
  74. axis for plot
  75. Returns
  76. -------
  77. ax: mpl axis
  78. axis for plot
  79. """
  80. if ax is None:
  81. # init figure
  82. f, ax = plt.subplots(figsize=figsize)
  83. # plot si vs depth
  84. ax.scatter(self.si_c, self.relative_depth, color='k', s=15, facecolor='none')
  85. ax.plot(self.si_c_smooth, self.relative_depth, color='r')
  86. for layer in self.layerY:
  87. ax.hlines(layer, 0, 1, color='k', linestyle='--')
  88. # layout
  89. ax.set_xlabel('Suppression index (SI)')
  90. ax.set_ylabel('Cortical depth to\nbase of L4 (mm)')
  91. ax.set_xlim(-0.05, 1.05)
  92. ax.set_ylim([(self.rel_layerDepth[0] - self.layerDepth[0]) / 1000, self.rel_layerDepth[
  93. -1] / 1000])
  94. ax.invert_yaxis()
  95. ax.set_yticks((-0.4, 0, 0.4))
  96. ax.set_xticks((0, 0.5, 1))
  97. ax.spines['bottom'].set_bounds(0, 1)
  98. f = plt.gcf()
  99. f.tight_layout()
  100. return ax