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

Skip to content

Commit 041a9ca

Browse files
authored
Merge pull request #7944 from dstansby/hexbin-speedup
Improve hexbin performance
2 parents 226729d + 949d657 commit 041a9ca

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,13 +4273,18 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
42734273
lattice1 = np.zeros((nx1, ny1))
42744274
lattice2 = np.zeros((nx2, ny2))
42754275

4276-
for i in xrange(len(x)):
4277-
if bdist[i]:
4278-
if 0 <= ix1[i] < nx1 and 0 <= iy1[i] < ny1:
4279-
lattice1[ix1[i], iy1[i]] += 1
4280-
else:
4281-
if 0 <= ix2[i] < nx2 and 0 <= iy2[i] < ny2:
4282-
lattice2[ix2[i], iy2[i]] += 1
4276+
cond1 = (0 <= ix1) * (ix1 < nx1) * (0 <= iy1) * (iy1 < ny1)
4277+
cond2 = (0 <= ix2) * (ix2 < nx2) * (0 <= iy2) * (iy2 < ny2)
4278+
4279+
cond1 *= bdist
4280+
cond2 *= np.logical_not(bdist)
4281+
ix1, iy1 = ix1[cond1], iy1[cond1]
4282+
ix2, iy2 = ix2[cond2], iy2[cond2]
4283+
4284+
for ix, iy in zip(ix1, iy1):
4285+
lattice1[ix, iy] += 1
4286+
for ix, iy in zip(ix2, iy2):
4287+
lattice2[ix, iy] += 1
42834288

42844289
# threshold
42854290
if mincnt is not None:

0 commit comments

Comments
 (0)