Home > OS >  Plotting data with binned_statistic_2d and sum showing unwanted values
Plotting data with binned_statistic_2d and sum showing unwanted values

Time:01-29

I'm plotting the energy distribution of lightning in the Med sea, and I'm plotting my data with imshow and binned_statistic_2d.

I successfully plotted the mean of the lightning energy, but for a reason, I can't understand the imshow plot is looking weird in the sum plot(colors unwanted areas with purple, see left plot in the image).

This is the code I'm using-

 plot_3vars_sum = binned_statistic_2d(longs, lats, energies, statistic= 'sum', bins=[467, 175])
plot_3vars_mean = binned_statistic_2d(longs, lats, energies, statistic=np.mean, bins=[467, 175])
ax0.plot(long_points_med, lat_points_med)
ax1.plot(long_points_med, lat_points_med)
imshow_sum = ax0.imshow(plot_3vars_sum.statistic.T, origin='lower', extent=[min(longs), max(longs), min(lats), max(lats)])
imshow_mean = ax1.imshow(plot_3vars_mean.statistic.T, origin='lower', extent=[min(longs), max(longs), min(lats), max(lats)])
ax0.set_ylim(ymin=28, ymax= 47)
ax1.set_ylim(ymin=28, ymax= 47)
ax0.set_xlim(xmin=-7, xmax=37)
ax1.set_xlim(xmin=-7, xmax=37)
imshow_sum.set_clim(1, 100000)
imshow_mean.set_clim(1, 10000)
cb0 = fig.colorbar(imshow_sum, ax=ax0, shrink=0.6)
cb1 = fig.colorbar(imshow_mean, ax=ax1, shrink=0.6)
plt.title(f'This is {month} in 2009-10')
plt.show()

longs, lats, and energies are simply lists of floats.

The image I'm getting is- enter image description here

I tried ignoring nans and setting the color bar limits to above 1, but nothing works... Can I get some help, please? I'm stuck.

Thanks in advance

CodePudding user response:

The reason for this behaviour is that when using mean, some of the bins contain "NaN" values while the result of "Sum" contains 0s. I'll try and find a way to make 0 into nan in the sum. question closed I guess? :-)

CodePudding user response:

The reason for this behaviour is that when using mean, some of the bins contain "NaN" values while the result of "Sum" contains 0s. I'll try and find a way to make 0 into nan in the sum. question closed I guess? :-)

  •  Tags:  
  • Related