napari-matplotlib icon indicating copy to clipboard operation
napari-matplotlib copied to clipboard

Allow adjustment of histogram bins

Open K-Meech opened this issue 2 years ago • 1 comments

It would be great to allow:

  • Adjustment of histogram bin width / locations via the UI
  • Using integer bin limits for integer images (e.g. uint8, uint16)

For example, if you show the coins image in Napari (File > Open Sample > napari builtins > Coins) and view the histogram, it has an odd 'spiky' appearance where every other bin is higher or lower: Screenshot 2023-12-14 121238

I think this is because the limits of the bins aren't set to integer values (even though this image is uint8 and therefore only contains positive integers). E.g. I think the bins are np.linspace(1, 252, 100) according to here, so for example bin 20 onwards is: 51.7, 54.2, 56.7, 59.3, 61.8, which means the bins accept pixel values of (52, 53, 54), (55, 56), (57, 58, 59), (60, 61)... This alternating of 2 and 3 pixel values in each bin gives this spiky appearance which is a bit misleading to the actual values. Would it be possible to set integer bin edges, or allow this to be set as an option? Thanks!

K-Meech avatar Dec 14 '23 12:12 K-Meech

👍 to doing this, a pull request that implements both suggestions (integer bins for integer data, and a bit of GUI to customise the bins) would be welcome. I'd recommend going with the integer bins first as that will require much less design work and be easier to implement.

dstansby avatar Jan 07 '24 21:01 dstansby