Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1344a90

Browse files
committed
Restore default behavior of hexbin mincnt with C provided
1 parent e501543 commit 1344a90

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Default behavior of ``hexbin`` with *C* provided requires at least 1 point
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The behavior changed in 3.8.0 to be inclusive of *mincnt*, however that resulted in
5+
errors or warnings with some reduction functions, so now the default is to require at
6+
least 1 point to call the reduction function. This effectively restores the default
7+
behavior to match that of Matplotlib 3.7 and before.

doc/api/prev_api_changes/api_changes_3.8.0/behaviour.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,9 @@ PostScript paper type adds option to use figure size
165165
The :rc:`ps.papertype` rcParam can now be set to ``'figure'``, which will use
166166
a paper size that corresponds exactly with the size of the figure that is being
167167
saved.
168+
169+
``hexbin`` *mincnt* parameter made consistently inclusive
170+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171+
172+
Previously, *mincnt* was inclusive with no *C* provided but exclusive when *C* is provided.
173+
It is now inclusive of *mincnt* in both cases.

lib/matplotlib/axes/_axes.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4873,8 +4873,8 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
48734873
yscale : {'linear', 'log'}, default: 'linear'
48744874
Use a linear or log10 scale on the vertical axis.
48754875
4876-
mincnt : int > 0, default: *None*
4877-
If not *None*, only display cells with more than *mincnt*
4876+
mincnt : int >= 0, default: *None*
4877+
If not *None*, only display cells with at least *mincnt*
48784878
number of points in the cell.
48794879
48804880
marginals : bool, default: *False*
@@ -4941,6 +4941,11 @@ def reduce_C_function(C: array) -> float
49414941
- `numpy.sum`: integral of the point values
49424942
- `numpy.amax`: value taken from the largest point
49434943
4944+
By default will only reduce cells with at least 1 point because some
4945+
reduction functions (such as `numpy.amax`) will error/warn with empty
4946+
input. Changing *mincnt* will adjust the cutoff, and if set to 0 will
4947+
pass empty input to the reduction function.
4948+
49444949
data : indexable object, optional
49454950
DATA_PARAMETER_PLACEHOLDER
49464951
@@ -5038,7 +5043,7 @@ def reduce_C_function(C: array) -> float
50385043
else:
50395044
Cs_at_i2[i2[i]].append(C[i])
50405045
if mincnt is None:
5041-
mincnt = 0
5046+
mincnt = 1
50425047
accum = np.array(
50435048
[reduce_C_function(acc) if len(acc) >= mincnt else np.nan
50445049
for Cs_at_i in [Cs_at_i1, Cs_at_i2]

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,8 @@ def test_hexbin_empty():
971971
# From #23922: creating hexbin with log scaling from empty
972972
# dataset raises ValueError
973973
ax.hexbin([], [], bins='log')
974+
# From #27103: np.max errors when handed empty data
975+
ax.hexbin([], [], C=[], reduce_C_function=np.max)
974976

975977

976978
def test_hexbin_pickable():

0 commit comments

Comments
 (0)