Skip to content

Conversation

@beckermr
Copy link
Collaborator

This PR fixes some unexpected behavior w/ hexbin.

  • The matplotlib hexbin parameter C has been mapped to the parameter weights in ultraplot.
  • For the majority (maybe all?) other histogram-like plots in ultraplot (and matplotlib) the weights are summed for the points in each bin (along with possibly a global normalization correction).
  • However, the default for hexbin is to average the weights in each bin.

This PR changes the default for hexbin to sum the weights in each bin so that the semantics of how weights are used is consistent across plotting functions.

Updated default behavior for weights/C to compute total instead of average.
@beckermr beckermr changed the title fix: change default reduce_C_function to np.sum for hexbin fix: change default reduce_C_function to np.sum for hexbin Nov 15, 2025
@beckermr beckermr requested a review from cvanelteren November 15, 2025 13:22
@codecov
Copy link

codecov bot commented Nov 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cvanelteren
Copy link
Collaborator

Can you add a test for this to run over the bin plots and ensure we have the same behavior?

Copy link
Collaborator

@cvanelteren cvanelteren left a comment

Choose a reason for hiding this comment

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

We need to add a test that ensures we are performing the same operations across the binned plots

@beckermr
Copy link
Collaborator Author

Any suggestions for how to write the test?

@cvanelteren
Copy link
Collaborator

cvanelteren commented Nov 16, 2025

I think we can do a simple check where take all hist related functions and check that the patches contain the sum; doesn't have to be super elaborate but just a safeguard for if this changes on mpl or our end in the future.

We could also check if what function is called with patches to see what the function put as input and check that this is a sum to ensure we are consistent across the board.

We may also need some smoke tests, like does passing a cumstom func properly propagate and set the values accordingly. This would not necessarily need a visual check.

@beckermr
Copy link
Collaborator Author

ok @cvanelteren this is ready for another look!

@beckermr beckermr requested a review from cvanelteren November 19, 2025 12:14
@cvanelteren
Copy link
Collaborator

Great thanks!

@beckermr beckermr enabled auto-merge (squash) November 19, 2025 12:28
@beckermr beckermr merged commit cad96d0 into main Nov 19, 2025
25 checks passed
@beckermr beckermr deleted the beckermr-patch-2 branch November 19, 2025 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants