@@ -322,30 +322,36 @@ def time_plots(particle, num_iter, folder_name=None):
322322 walk_data = particle .run_iteration ()
323323
324324 # collect latest travel times
325- x0 , y0 , t0 = get_state (walk_data , 0 )
326325 xi , yi , temptimes = get_state (walk_data )
327326
328- # set colorbar using 10th and 90th percentile values
329- cm = matplotlib .cm .colors .Normalize (vmax = np .percentile (temptimes , 90 ),
330- vmin = np .percentile (temptimes , 10 ))
331-
332- fig = plt .figure (dpi = 200 )
333- ax = plt .gca ()
334- plt .title ('Depth - Particle Iteration ' + str (i ))
335- ax .scatter (y0 , x0 , c = 'b' , s = 0.75 )
336- sc = ax .scatter (yi , xi , c = temptimes , s = 0.75 , cmap = 'coolwarm' , norm = cm )
337- divider = make_axes_locatable (ax )
338- cax = divider .append_axes ("right" , size = "5%" , pad = 0.05 )
339- cbar = plt .colorbar (sc , cax = cax )
340- cbar .set_label ('Particle Travel Times [s]' )
341- im = ax .imshow (particle .depth )
342- divider = make_axes_locatable (ax )
343- cax = divider .append_axes ("bottom" , size = "5%" , pad = 0.5 )
344- cbar2 = plt .colorbar (im , cax = cax , orientation = 'horizontal' )
345- cbar2 .set_label ('Water Depth [m]' )
327+ if i == 0 :
328+ x0 , y0 , t0 = get_state (walk_data , 0 )
329+ # Initialize figure
330+ fig = plt .figure (dpi = 200 )
331+ ax = plt .gca ()
332+ im = ax .imshow (particle .depth )
333+ orig = ax .scatter (y0 , x0 , c = 'b' , s = 0.75 )
334+ sc = ax .scatter (yi , xi , c = temptimes , s = 0.75 , cmap = 'coolwarm' )
335+ sc .set_clim (np .percentile (temptimes ,90 ),
336+ np .percentile (temptimes ,10 ))
337+ divider = make_axes_locatable (ax )
338+ cax = divider .append_axes ("right" , size = "5%" , pad = 0.05 )
339+ cbar = plt .colorbar (sc , cax = cax )
340+ cbar .set_label ('Particle Travel Times [s]' )
341+ divider = make_axes_locatable (ax )
342+ cax = divider .append_axes ("bottom" , size = "5%" , pad = 0.5 )
343+ cbar2 = plt .colorbar (im , cax = cax , orientation = 'horizontal' )
344+ cbar2 .set_label ('Water Depth [m]' )
345+ else :
346+ # Update figure with new locations
347+ sc .set_offsets (np .array ([yi ,xi ]).T ) # Location
348+ sc .set_array (np .array (temptimes )) # Color values
349+ sc .set_clim (np .percentile (temptimes ,90 ),
350+ np .percentile (temptimes ,10 )) # Color limits
351+ plt .draw ()
352+ ax .set_title ('Depth - Particle Iteration ' + str (i ))
346353 plt .savefig (folder_name + os .sep + 'figs' + os .sep + 'output' + str (i )+ '.png' ,
347354 bbox_inches = 'tight' )
348- plt .close ()
349355
350356 # save data as a json text file - technically human readable
351357 fpath = folder_name + os .sep + 'data' + os .sep + 'data.txt'
0 commit comments