55from scipy .ndimage .measurements import center_of_mass
66
77
8- def plot_path (x , y , t , box_size , spike_times = None ,
9- color = 'grey' , alpha = 0.5 , origin = 'upper' ,
10- spike_color = 'r' , rate_markersize = False , markersize = 10. ,
11- animate = False , ax = None ):
8+ def plot_path (
9+ x ,
10+ y ,
11+ t ,
12+ box_size ,
13+ spike_times = None ,
14+ color = "grey" ,
15+ alpha = 0.5 ,
16+ origin = "upper" ,
17+ spike_color = "r" ,
18+ rate_markersize = False ,
19+ markersize = 10.0 ,
20+ animate = False ,
21+ ax = None ,
22+ ):
1223 """
1324 Plot path visited
1425
@@ -39,8 +50,7 @@ def plot_path(x, y, t, box_size, spike_times=None,
3950 """
4051 if ax is None :
4152 fig = plt .figure ()
42- ax = fig .add_subplot (
43- 111 , xlim = [0 , box_size ], ylim = [0 , box_size ], aspect = 1 )
53+ ax = fig .add_subplot (111 , xlim = [0 , box_size ], ylim = [0 , box_size ], aspect = 1 )
4454
4555 ax .plot (x , y , c = color , alpha = alpha )
4656 if spike_times is not None :
@@ -49,20 +59,36 @@ def plot_path(x, y, t, box_size, spike_times=None,
4959
5060 if rate_markersize :
5161 markersize = spikes_in_bin [is_spikes_in_bin ] * markersize
52- ax .scatter (x [:- 1 ][is_spikes_in_bin ], y [:- 1 ][is_spikes_in_bin ],
53- facecolor = spike_color , edgecolor = spike_color ,
54- s = markersize )
62+ ax .scatter (
63+ x [:- 1 ][is_spikes_in_bin ],
64+ y [:- 1 ][is_spikes_in_bin ],
65+ facecolor = spike_color ,
66+ edgecolor = spike_color ,
67+ s = markersize ,
68+ )
5569
5670 ax .grid (False )
57- if origin == ' upper' :
71+ if origin == " upper" :
5872 ax .invert_yaxis ()
5973 return ax
6074
6175
62- def animate_path (x , y , t , box_size , spike_times = None ,
63- color = 'grey' , alpha = 0.5 , origin = 'upper' ,
64- spike_color = 'r' , rate_markersize = False , markersize = 10. ,
65- animate = False , ax = None , title = '' ):
76+ def animate_path (
77+ x ,
78+ y ,
79+ t ,
80+ box_size ,
81+ spike_times = None ,
82+ color = "grey" ,
83+ alpha = 0.5 ,
84+ origin = "upper" ,
85+ spike_color = "r" ,
86+ rate_markersize = False ,
87+ markersize = 10.0 ,
88+ animate = False ,
89+ ax = None ,
90+ title = "" ,
91+ ):
6692 """
6793 Plot path visited
6894
@@ -93,35 +119,35 @@ def animate_path(x, y, t, box_size, spike_times=None,
93119 """
94120 if ax is None :
95121 fig = plt .figure ()
96- ax = fig .add_subplot (
97- 111 , xlim = [0 , box_size ], ylim = [0 , box_size ], aspect = 1 )
122+ ax = fig .add_subplot (111 , xlim = [0 , box_size ], ylim = [0 , box_size ], aspect = 1 )
98123 if spike_times is not None :
99124 spikes_in_bin , _ = np .histogram (spike_times , t )
100125 is_spikes_in_bin = np .array (spikes_in_bin , dtype = bool )
101126
102127 if rate_markersize :
103- markersizes = spikes_in_bin [is_spikes_in_bin ]* markersize
128+ markersizes = spikes_in_bin [is_spikes_in_bin ] * markersize
104129 else :
105- markersizes = markersize * np .ones (is_spikes_in_bin .size )
130+ markersizes = markersize * np .ones (is_spikes_in_bin .size )
106131 ax .set_title (title )
107132 ax .grid (False )
108- if origin == ' upper' :
133+ if origin == " upper" :
109134 ax .invert_yaxis ()
110135 import time
136+
111137 plt .show ()
112138 for idx , x , y , active , msize in zip (range (len (x )), x , y ):
113139 ax .plot (x , y , c = color , alpha = alpha )
114140 if spike_times is not None :
115141 if is_spikes_in_bin [idx ]:
116- ax .scatter (x , y , facecolor = spike_color , edgecolor = spike_color ,
117- s = markersizes [idx ])
142+ ax .scatter (x , y , facecolor = spike_color , edgecolor = spike_color , s = markersizes [idx ])
118143 time .sleep (0.1 ) # plt.pause(0.0001)
119144 plt .draw ()
120145 return ax
121146
122147
123- def plot_head_direction_rate (spike_times , ang_bins , rate_in_ang , projection = 'polar' ,
124- normalization = False , ax = None , color = 'k' ):
148+ def plot_head_direction_rate (
149+ spike_times , ang_bins , rate_in_ang , projection = "polar" , normalization = False , ax = None , color = "k"
150+ ):
125151 """
126152
127153
@@ -142,26 +168,38 @@ def plot_head_direction_rate(spike_times, ang_bins, rate_in_ang, projection='pol
142168 out : ax
143169 """
144170 import math
171+
145172 if normalization :
146- rate_in_ang = normalize (rate_in_ang , mode = ' minmax' )
173+ rate_in_ang = normalize (rate_in_ang , mode = " minmax" )
147174 if ax is None :
148175 fig = plt .figure ()
149176 ax = fig .add_subplot (111 , projection = projection )
150177 bin_size = ang_bins [1 ] - ang_bins [0 ]
151178 if projection is None :
152179 ax .set_xticks (range (0 , 360 + 60 , 60 ))
153180 ax .set_xlim (0 , 360 )
154- elif projection == ' polar' :
181+ elif projection == " polar" :
155182 ang_bins = [math .radians (deg ) for deg in ang_bins ]
156183 bin_size = math .radians (bin_size )
157184 ax .set_xticks ([0 , np .pi ])
158185 ax .bar (ang_bins , rate_in_ang , width = bin_size , color = color )
159186 return ax
160187
161188
162- def plot_ratemap (x , y , t , spike_times , bin_size = 0.05 , box_size = 1 ,
163- box_size = 1 , vmin = 0 , ax = None , smoothing = .05 ,
164- origin = 'upper' , cmap = 'viridis' ):
189+ def plot_ratemap (
190+ x ,
191+ y ,
192+ t ,
193+ spike_times ,
194+ bin_size = 0.05 ,
195+ box_size = 1 ,
196+ box_size = 1 ,
197+ vmin = 0 ,
198+ ax = None ,
199+ smoothing = 0.05 ,
200+ origin = "upper" ,
201+ cmap = "viridis" ,
202+ ):
165203 """
166204
167205
@@ -184,19 +222,17 @@ def plot_ratemap(x, y, t, spike_times, bin_size=0.05, box_size=1,
184222 fig = plt .figure ()
185223 ax = fig .add_subplot (111 , xlim = [0 , 1 ], ylim = [0 , 1 ], aspect = 1 )
186224
187- map = SpatialMap (
188- x , y , t , spike_times , bin_size = bin_size , box_size = box_size )
225+ map = SpatialMap (x , y , t , spike_times , bin_size = bin_size , box_size = box_size )
189226 rate_map = map .rate_map (smoothing )
190- ax .imshow (rate_map , interpolation = 'none' , origin = origin ,
191- extent = (0 , 1 , 0 , 1 ), vmin = vmin , cmap = cmap )
192- ax .set_title ('%.2f Hz' % np .nanmax (rate_map ))
227+ ax .imshow (rate_map , interpolation = "none" , origin = origin , extent = (0 , 1 , 0 , 1 ), vmin = vmin , cmap = cmap )
228+ ax .set_title ("%.2f Hz" % np .nanmax (rate_map ))
193229 ax .grid (False )
194230 return ax
195231
196232
197- def plot_occupancy (x , y , t , bin_size = 0.05 , box_size = 1 , box_size = 1 ,
198- vmin = 0 , ax = None , convolve = True ,
199- origin = 'upper' , cmap = 'jet' ):
233+ def plot_occupancy (
234+ x , y , t , bin_size = 0.05 , box_size = 1 , box_size = 1 , vmin = 0 , ax = None , convolve = True , origin = "upper" , cmap = "jet"
235+ ):
200236 """
201237
202238
@@ -219,10 +255,10 @@ def plot_occupancy(x, y, t, bin_size=0.05, box_size=1, box_size=1,
219255 fig = plt .figure ()
220256 ax = fig .add_subplot (111 , xlim = [0 , 1 ], ylim = [0 , 1 ], aspect = 1 )
221257
222- occ_map = occupancy_map (x , y , t , bin_size = bin_size , box_size = box_size ,
223- box_size = box_size , convolve = convolve )
224- cax = ax . imshow ( occ_map , interpolation = ' none' , origin = origin ,
225- extent = ( 0 , 1 , 0 , 1 ), vmin = vmin , cmap = cmap , aspect = 'auto' )
258+ occ_map = occupancy_map (x , y , t , bin_size = bin_size , box_size = box_size , box_size = box_size , convolve = convolve )
259+ cax = ax . imshow (
260+ occ_map , interpolation = " none" , origin = origin , extent = ( 0 , 1 , 0 , 1 ), vmin = vmin , cmap = cmap , aspect = "auto"
261+ )
226262 # ax.set_title('%.2f s' % np.nanmax(occ_map))
227263 ax .grid (False )
228264 return cax , np .nanmax (occ_map )
0 commit comments