Skip to content

Add widgets for setting histogram bins #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jul 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a7b09d4
Add widgets to set bin parameters for histograms
p-j-smith Jan 11, 2024
96b2f0c
Add test for histogram widget when setting bin parameters
p-j-smith Jan 11, 2024
b8623ed
Update changelog
p-j-smith Jan 11, 2024
4e4fb84
Make linters happy
p-j-smith Jan 11, 2024
5ac1f71
Fix type hints
p-j-smith Jan 11, 2024
fab2906
Don't allow bins lower than 0 if dtype is unisgned
p-j-smith Jan 11, 2024
5553174
Update changelog
p-j-smith Jan 11, 2024
e86d4f6
Undo changes to example of HistogramWidget
p-j-smith Jan 11, 2024
c5e0886
Fix autosetting bins from data
p-j-smith Jan 15, 2024
127d325
remove duplicate on_update_layers method
p-j-smith Jan 15, 2024
b8ffdb7
Make linters happy
p-j-smith Jan 15, 2024
88760cf
Add HistogramWidget._bin_widgets attribute for storing bin widgets
p-j-smith Jan 15, 2024
d56942b
Fix calculation of bins from widget values
p-j-smith Jan 15, 2024
11590b2
Calculate step using n_bins-1
p-j-smith Jan 15, 2024
08a5086
cannot use negative start bin for uint data
p-j-smith Jan 15, 2024
65e84f8
Make HistogramWidget bins_num widget correspond to number of bins rat…
p-j-smith Jan 15, 2024
37d33ae
Merge branch 'main' into feat/hist-bin-params
p-j-smith Jan 15, 2024
8a7d9e4
fix typo in comment about using 128 bins for float data
p-j-smith Jan 15, 2024
fbd929e
Merge branch 'main' into feat/hist-bin-params
p-j-smith Jan 15, 2024
7c4cdc8
Update changelog
p-j-smith Jan 15, 2024
c6b5d8e
Merge branch 'main' into feat/hist-bin-params
p-j-smith Feb 14, 2024
6261f4c
Add 'num_bins, 'start', and 'stop' parameters to '_get_bins'
p-j-smith Feb 14, 2024
457bc1b
Merge branch 'main' into feat/hist-bin-params
p-j-smith May 25, 2024
426a0f5
use '| None' rather than Optional[Union[...]] for type hints
p-j-smith May 25, 2024
67a8641
remove widgest to set start and stop values for histogram bins
p-j-smith May 25, 2024
208af97
Merge branch 'main' into feat/hist-bin-params
dstansby Jul 12, 2024
8fe7c7f
Update changelog
dstansby Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make linters happy
  • Loading branch information
p-j-smith committed Jan 15, 2024
commit b8ffdb79a7c20fe0ceaf7b9a0dbd8174c52c63ec
6 changes: 3 additions & 3 deletions src/napari_matplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ def _update_contrast_lims(self) -> None:

def autoset_widget_bins(self, data: npt.NDArray[Any]) -> None:
"""Update widgets with bins determined from the image data"""

if data.dtype.kind in {"i", "u"}:
# Make sure integer data types have integer sized bins
# We can't use unsigned ints when calculating the step, otherwise
# the following warning is raised:
# 'RuntimeWarning: overflow encountered in scalar subtract'
step = abs(np.min(data).astype(int) - np.max(data).astype(int) // 100)
step = abs(
np.min(data).astype(int) - np.max(data).astype(int) // 100
)
step = max(1, step)
bins = np.arange(np.min(data), np.max(data) + step, step)
else:
Expand All @@ -141,7 +142,6 @@ def autoset_widget_bins(self, data: npt.NDArray[Any]) -> None:
self.bins_stop = bins[-1]
self.bins_num = bins.size


@property
def bins_start(self) -> float:
"""Minimum bin edge"""
Expand Down