Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dstansby merged 27 commits intomatplotlib:mainfromp-j-smith:feat/hist-bin-params
Jul 12, 2024

Conversation

p-j-smith
Copy link
Contributor

@p-j-smithp-j-smith commentedJan 11, 2024
edited
Loading

Fixes#239

  • addedQDoubleSpinBox widgets for setting the start and stop edges of the histogram bins (default to the min and max data values, same as existing values used)
  • added aQSpinBox widget for setting the number of bins to use (defaults to 100, same as the existing value used)
  • add callbacks to re-draw figure when value of widgets change
  • set thedtype fornp.linspace when creating bins (so integer bin limits are used for integer images). This caused thetest_histogram_2D test to fail (as the test layer has integer data but float bins were being used) so I've updated the baseline image - this is now done inUse integer bins for integer data inHistogramWidget #244
  • added a test for theHistogramWidget when the bin parameters are set from the widgets
  • addstart,stop, andnum_bins parameters to_get_bins function so that bin parameters set in the widgets can be used for settings bins
  • show notification if the bin parameters requested by the user have been modified before plotting (this can happen with integer data as we need to make sure the bins have integer widths)
napari-mpl-hist-bins.mov

@p-j-smithp-j-smith marked this pull request as draftJanuary 11, 2024 11:51
@dstansby
Copy link
Member

Thanks for the PR! Could you put the integer dtype histogram change into a separate PR to make it easier to review?

p-j-smith reacted with thumbs up emoji

@dstansbydstansby added this to the2.0 milestoneJan 11, 2024
@p-j-smith
Copy link
ContributorAuthor

Could you put the integer dtype histogram change into a separate PR to make it easier to review?

Yep, will do 🙂

bins_start = QDoubleSpinBox()
bins_start.setObjectName("bins start")
bins_start.setStepType(QAbstractSpinBox.AdaptiveDecimalStepType)
bins_start.setRange(-1e10, 1e10)
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I wasn't sure what a reasonable range would be (rather than the default of 0 to 100)?

Comment on lines 151 to 162
# Only allow integer bins for integer data
# And only allow values greater than 0 for unsigned integers
n_decimals = 0 if np.issubdtype(layer_data.dtype, np.integer) else 2
is_unsigned = layer_data.dtype.kind == "u"
minimum_value = 0 if is_unsigned else -1e10

bins_start = self.findChild(QDoubleSpinBox, name="bins start")
bins_stop = self.findChild(QDoubleSpinBox, name="bins stop")
bins_start.setDecimals(n_decimals)
bins_stop.setDecimals(n_decimals)
bins_start.setMinimum(minimum_value)
bins_stop.setMinimum(minimum_value)
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

it's necessary to set the minimum bin values to 0 for unsigned integers - if negative bin limits are selected for data with unsigned integers,plt.hist complains that bins must be monotonically increasing (as there's an integer underflow in the bins produced bynp.linspace)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

it's not necessary to set the decimals to 0 for integers, but makes it clear to the users that the data are integers and float bin limits are not appropriate

@dstansbydstansby added New featureNew feature or request Changelog needed labelsJan 11, 2024
@dstansbydstansby modified the milestones:2.0,2.1Jan 15, 2024
@p-j-smithp-j-smith marked this pull request as ready for reviewJanuary 15, 2024 17:10
@p-j-smithp-j-smith marked this pull request as draftJanuary 15, 2024 17:12
Comment on lines 125 to 135
# Disable callbacks whilst widget values might change
for widget in self._bin_widgets.values():
widget.blockSignals(True)

self._bin_widgets["start"].setDecimals(n_decimals)
self._bin_widgets["stop"].setDecimals(n_decimals)
self._bin_widgets["start"].setMinimum(minimum_value)
self._bin_widgets["stop"].setMinimum(minimum_value)

for widget in self._bin_widgets.values():
widget.blockSignals(False)
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

temporarily disable the callbacks otherwise the plot is re-drawn each time the widget value changes

@p-j-smithp-j-smith marked this pull request as ready for reviewJanuary 15, 2024 17:14
Comment on lines 213 to 217
if data.dtype.kind in {"i", "u"}:
# Make sure integer data types have integer sized bins
step = abs(self.bins_stop - self.bins_start) // (self.bins_num)
step = max(1, step)
bins = np.arange(self.bins_start, self.bins_stop + step, step)
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think it would be good to show a notification when the actual number of bins used differs from that requested in the widgets, but perhaps this could be a different PR?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I've added the notification now, but happy to remove it and add separately if it's easier

@p-j-smithp-j-smith marked this pull request as draftJanuary 15, 2024 17:26
@p-j-smithp-j-smith marked this pull request as ready for reviewFebruary 14, 2024 11:24
@dstansby
Copy link
Member

I am finally thinking about this (sorry it took so long!), and my current thoughts are to keep things simple we should just have a setting for the number of bins, and show the full range of data without being able to control the start/stop. I am open to adding confiurable start/stop in the futureif there's a compelling use case, but for now I think configuring the number of bins is a nice feature that isn't too complicated by itself.

Would you be able to update this PR (or open a new one) to just have the number of bins configurable? Obviously no rush at all 😄, but let me know if it isn't likely to be soon in case I get the bug to implement it

@p-j-smith
Copy link
ContributorAuthor

Yeah good idea, it became surprisingly complicated! I've removed the notification of requested vs actual bins that I previously added (you can see it in the video above) , do you want it added back?

@dstansbydstansby removed this from the2.1 milestoneJul 12, 2024
Copy link
Member

@dstansbydstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry this has taken so long to get to, but I gave it a try and it looks 👍👍👍👍 . I've mergedmain into here, and will update the changelog entry, then get this in a release 😄

p-j-smith reacted with laugh emoji
@dstansbydstansbyenabled auto-mergeJuly 12, 2024 14:25
@dstansbydstansby merged commit251d333 intomatplotlib:mainJul 12, 2024
13 checks passed
@p-j-smith
Copy link
ContributorAuthor

Sorry this has taken so long to get to,

no worries 😄 Thanks for the reviews and for merging it!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dstansbydstansbydstansby approved these changes

Assignees
No one assigned
Labels
New featureNew feature or request
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Allow adjustment of histogram bins
2 participants
@p-j-smith@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp