Skip to content

Commit 584cda0

Browse files
authored
Merge pull request #26113 from krooijers/bugfix-for-issue-12926
Fixes #12926 - inconsistency upon passing C in hexbin
2 parents 475612e + 7ce6a69 commit 584cda0

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5014,7 +5014,7 @@ def reduce_C_function(C: array) -> float
50145014
if mincnt is None:
50155015
mincnt = 0
50165016
accum = np.array(
5017-
[reduce_C_function(acc) if len(acc) > mincnt else np.nan
5017+
[reduce_C_function(acc) if len(acc) >= mincnt else np.nan
50185018
for Cs_at_i in [Cs_at_i1, Cs_at_i2]
50195019
for acc in Cs_at_i[1:]], # [1:] drops out-of-range points.
50205020
float)

lib/matplotlib/tests/test_axes.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,45 @@ def test_hexbin_log_clim():
999999
assert h.get_clim() == (2, 100)
10001000

10011001

1002+
@check_figures_equal(extensions=['png'])
1003+
def test_hexbin_mincnt_behavior_upon_C_parameter(fig_test, fig_ref):
1004+
# see: gh:12926
1005+
datapoints = [
1006+
# list of (x, y)
1007+
(0, 0),
1008+
(0, 0),
1009+
(6, 0),
1010+
(0, 6),
1011+
]
1012+
X, Y = zip(*datapoints)
1013+
C = [1] * len(X)
1014+
extent = [-10., 10, -10., 10]
1015+
gridsize = (7, 7)
1016+
1017+
ax_test = fig_test.subplots()
1018+
ax_ref = fig_ref.subplots()
1019+
1020+
# without C parameter
1021+
ax_ref.hexbin(
1022+
X, Y,
1023+
extent=extent,
1024+
gridsize=gridsize,
1025+
mincnt=1,
1026+
)
1027+
ax_ref.set_facecolor("green") # for contrast of background
1028+
1029+
# with C parameter
1030+
ax_test.hexbin(
1031+
X, Y,
1032+
C=[1] * len(X),
1033+
reduce_C_function=lambda v: sum(v),
1034+
mincnt=1,
1035+
extent=extent,
1036+
gridsize=gridsize,
1037+
)
1038+
ax_test.set_facecolor("green")
1039+
1040+
10021041
def test_inverted_limits():
10031042
# Test gh:1553
10041043
# Calling invert_xaxis prior to plotting should not disable autoscaling

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy