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

Skip to content

Commit 1472dfc

Browse files
committed
Merge pull request #3038 from tacaswell/hexbin_singular
BUG : expand x/y range in hexbin if singular
2 parents ef462e4 + b6ddb45 commit 1472dfc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import matplotlib.ticker as mticker
3737
import matplotlib.transforms as mtransforms
3838
import matplotlib.tri as mtri
39+
import matplotlib.transforms as mtrans
3940
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
4041
from matplotlib.axes._base import _AxesBase
4142

@@ -3742,6 +3743,10 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
37423743
xmax = np.amax(x)
37433744
ymin = np.amin(y)
37443745
ymax = np.amax(y)
3746+
# to avoid issues with singular data, expand the min/max pairs
3747+
xmin, xmax = mtrans.nonsingular(xmin, xmax, expander=0.1)
3748+
ymin, ymax = mtrans.nonsingular(ymin, ymax, expander=0.1)
3749+
37453750
# In the x-direction, the hexagons exactly cover the region from
37463751
# xmin to xmax. Need some padding to avoid roundoff errors.
37473752
padding = 1.e-9 * (xmax - xmin)

lib/matplotlib/tests/test_axes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from matplotlib.testing.decorators import image_comparison, cleanup
1515
import matplotlib.pyplot as plt
1616
from numpy.testing import assert_array_equal
17+
import warnings
18+
1719

1820
@image_comparison(baseline_images=['formatter_ticker_001',
1921
'formatter_ticker_002',
@@ -2990,6 +2992,17 @@ def test_pie_ccw_true():
29902992
plt.axis('equal')
29912993

29922994

2995+
@cleanup
2996+
def test_pathological_hexbin():
2997+
# issue #2863
2998+
with warnings.catch_warnings(record=True) as w:
2999+
mylist = [10] * 100
3000+
fig, ax = plt.subplots(1, 1)
3001+
ax.hexbin(mylist, mylist)
3002+
plt.show()
3003+
assert_equal(len(w), 0)
3004+
3005+
29933006
if __name__ == '__main__':
29943007
import nose
29953008
import sys

0 commit comments

Comments
 (0)