figS6.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # code to plot figure S6
  2. # import
  3. import matplotlib.pyplot as plt
  4. from importlib import reload
  5. import pandas
  6. import spatint_utils
  7. import os
  8. # reload modules
  9. reload(spatint_utils)
  10. # load plot params
  11. spatint_utils.plot_params()
  12. class FigS6:
  13. """Class for plotting panels of Fig. S6"""
  14. def __init__(self):
  15. """Init class"""
  16. parentdir = os. path. dirname(os. getcwd())
  17. # read lgn size tuning dataframe
  18. self.lgn_sztun_df = pandas.read_pickle(
  19. filepath_or_buffer=parentdir + '/data/lgn_sztun_df.pkl')
  20. def ex_curves(self, figsize=(5, 2), axs=None):
  21. """Plot example dLGN size tuning curves (Fig. S6 a-j)
  22. Parameters
  23. -------
  24. figsize: tuple
  25. Figure size (width, height)
  26. axs: mpl axis
  27. axes for plot
  28. Returns
  29. -------
  30. ax: mpl axis
  31. axis for plot
  32. """
  33. if axs is None:
  34. # init figure
  35. f, axs = plt.subplots(2, 5, figsize=figsize)
  36. # determine example keys
  37. exkeys = [{'m': 'PVCre_2013_0046', 's': 8, 'e': 9, 'u': 3038}, # a
  38. {'m': 'PVCre_2013_0046', 's': 6, 'e': 6, 'u': 4042}, # b
  39. {'m': 'PVCre_2013_0046', 's': 8, 'e': 12, 'u': 3030}, # c
  40. {'m': 'PVCre_2013_0054', 's': 10, 'e': 4, 'u': 2073}, # d
  41. {'m': 'PVCre_2013_0046', 's': 8, 'e': 14, 'u': 3039}, # e
  42. {'m': 'PVCre_2013_0054', 's': 10, 'e': 5, 'u': 1048}, # f
  43. {'m': 'PVCre_2013_0046', 's': 5, 'e': 7, 'u': 3037}, # g
  44. {'m': 'PVCre_2013_0054', 's': 11, 'e': 4, 'u': 3016}, # h
  45. {'m': 'PVCre_2020_0002', 's': 6, 'e': 5, 'u': 4}, # i
  46. {'m': 'PVCre_2013_0046', 's': 6, 'e': 6, 'u': 4040}] # j
  47. # loop over example keys and plot
  48. for ax, exkey in zip(axs.flatten(), exkeys):
  49. ex_row = self.lgn_sztun_df[(self.lgn_sztun_df.m == exkey['m']) &
  50. (self.lgn_sztun_df.s == exkey['s']) &
  51. (self.lgn_sztun_df.e == exkey['e']) &
  52. (self.lgn_sztun_df.u == exkey['u'])].iloc[0]
  53. spatint_utils.plot_tun(means=ex_row['tun_mean'],
  54. sems=ex_row['tun_sem'],
  55. spons=ex_row['tun_spon_mean'],
  56. xs=ex_row['ti_axes'],
  57. c_fit=ex_row['c_sz_fit'],
  58. op_fit=ex_row['op_sz_fit'],
  59. c_prefsz=ex_row['rfcs_76'][0],
  60. op_prefsz=ex_row['rfcs_76'][1],
  61. ax=ax)
  62. # layout
  63. max_x = 76
  64. ax.set_xlim(-3, max_x)
  65. ax.set_xticks([0, 25, 50, 75])
  66. ax.spines['bottom'].set_bounds(0, max_x)
  67. yticks = ax.get_yticks()
  68. ax.set_yticks((yticks[0], int((yticks[-1] - 5) / 2), yticks[-1] - 5))
  69. ax.set_ylabel('')
  70. ax.set_xlabel('')
  71. ax.set_xticklabels([])
  72. axs.flatten()[5].set_ylabel('Firing rate (sp/s)')
  73. axs.flatten()[5].set_xlabel('Diameter ($\degree$)')#
  74. axs.flatten()[5].set_xticklabels([0, 25, 50, 75])
  75. f = plt.gcf()
  76. f.tight_layout()
  77. return axs