Commits

Alexander Konovalov committed 58218d6

Scattering diagrams are now properly normalized

Comments (0)

Files changed (1)

utils/plot_scattering.py

     scatter_angles = (np.arange(scatter_points) + 0.5) * angle_delta
     scatter_areas = 2 * np.pi * ((1 - np.cos(scatter_angles + 0.5 * angle_delta)) - (1 - np.cos(scatter_angles - 0.5 * angle_delta)))
 
-    scatter_data = np.append(scatter_data[:, ::-1], scatter_data, axis=1) / 2
+    scatter_data = np.append(scatter_data[:, ::-1], scatter_data, axis=1) / angle_delta
     scatter_angles = np.append(-scatter_angles[::-1], scatter_angles, axis=0)
     scatter_areas = np.append(scatter_areas[::-1], scatter_areas, axis=0)
-    print (scatter_areas)
 
     # force square figure and square axes looks better for polar, IMO
     width, height = plt.rcParams['figure.figsize']
     size = min(width, height)
     fig = plt.figure(figsize=(size, size))
-    ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c')
+    ax = fig.add_axes([0.2, 0.2, 0.70, 0.70], polar=True, axisbg='#d5de9c')
     plt.grid(True)
-    ax.set_title("n = %s" % n_data[0], fontsize=15)
 
     current_index = 0
     current_distr_type = 'per angle'
     plot = None
 
     def update_plot():
-        global scatter_data, scatter_areas
-        global current_index, plot
+        global plot
         plot_data = np.array(scatter_data[current_index,:])
         if current_distr_type == 'per area':
-            plot_data /= scatter_areas
+            plot_data = plot_data * angle_delta / scatter_areas
 
         if plot == None:
             plot, = ax.plot(scatter_angles, plot_data, color='#ee8d18', lw=3)
         else:
             plot.set_ydata(plot_data)
         ax.set_rmax(plot_data.max())
+        ax.set_title("n = %s" % n_data[current_index], fontsize=15)
     update_plot()
 
-    index_slider = Slider(plt.axes([0.25, 0.1, 0.65, 0.03]), 'n', n_data.min(), n_data.max(), valinit=n_data[current_index])
+    index_slider = Slider(plt.axes([0.1, 0.1, 0.8, 0.03]), 'n', n_data.min(), n_data.max(), valinit=n_data[current_index])
     def update_index(val):
         global current_index
         current_index = np.argmin((n_data - index_slider.val)**2)
         plt.draw()
     index_slider.on_changed(update_index)
 
-    radio = RadioButtons(plt.axes([0.025, 0.5, 0.15, 0.15]), ('per angle', 'per area'), active=0)
+    radio = RadioButtons(plt.axes([0.025, 0.8, 0.20, 0.15]), ('per angle', 'per area'), active=0)
     def update_distr_type(label):
         global current_distr_type
         current_distr_type = label