Restore default behavior of hexbin mincnt with C provided by ksunden · Pull Request #27179 · matplotlib/matplotlib · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions doc/api/next_api_changes/behavior/27179-KS.rst
6 changes: 6 additions & 0 deletions doc/api/prev_api_changes/api_changes_3.8.0/behaviour.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,9 @@ PostScript paper type adds option to use figure size
The :rc:`ps.papertype` rcParam can now be set to ``'figure'``, which will use
a paper size that corresponds exactly with the size of the figure that is being
saved.

``hexbin`` *mincnt* parameter made consistently inclusive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Previously, *mincnt* was inclusive with no *C* provided but exclusive when *C* is provided.
It is now inclusive of *mincnt* in both cases.
11 changes: 8 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4873,8 +4873,8 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
yscale : {'linear', 'log'}, default: 'linear'
Use a linear or log10 scale on the vertical axis.

mincnt : int > 0, default: *None*
If not *None*, only display cells with more than *mincnt*
mincnt : int >= 0, default: *None*
If not *None*, only display cells with at least *mincnt*
Comment thread
rcomer marked this conversation as resolved.
number of points in the cell.

marginals : bool, default: *False*
Expand Down Expand Up @@ -4941,6 +4941,11 @@ def reduce_C_function(C: array) -> float
- `numpy.sum`: integral of the point values
- `numpy.amax`: value taken from the largest point

By default will only reduce cells with at least 1 point because some
reduction functions (such as `numpy.amax`) will error/warn with empty
input. Changing *mincnt* will adjust the cutoff, and if set to 0 will
pass empty input to the reduction function.

data : indexable object, optional
DATA_PARAMETER_PLACEHOLDER

Expand Down Expand Up @@ -5038,7 +5043,7 @@ def reduce_C_function(C: array) -> float
else:
Cs_at_i2[i2[i]].append(C[i])
if mincnt is None:
mincnt = 0
mincnt = 1
accum = np.array(
[reduce_C_function(acc) if len(acc) >= mincnt else np.nan
for Cs_at_i in [Cs_at_i1, Cs_at_i2]
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/tests/test_axes.py