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

Skip to content

BUG : expand x/y range in hexbin if singular #3038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2014
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
5 changes: 5 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import matplotlib.ticker as mticker
import matplotlib.transforms as mtransforms
import matplotlib.tri as mtri
import matplotlib.transforms as mtrans
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
from matplotlib.axes._base import _AxesBase

Expand Down Expand Up @@ -3762,6 +3763,10 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
xmax = np.amax(x)
ymin = np.amin(y)
ymax = np.amax(y)
# to avoid issues with singular data, expand the min/max pairs
xmin, xmax = mtrans.nonsingular(xmin, xmax, expander=0.1)
ymin, ymax = mtrans.nonsingular(ymin, ymax, expander=0.1)

# In the x-direction, the hexagons exactly cover the region from
# xmin to xmax. Need some padding to avoid roundoff errors.
padding = 1.e-9 * (xmax - xmin)
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from matplotlib.testing.decorators import image_comparison, cleanup
import matplotlib.pyplot as plt
from numpy.testing import assert_array_equal
import warnings


@image_comparison(baseline_images=['formatter_ticker_001',
'formatter_ticker_002',
Expand Down Expand Up @@ -2990,6 +2992,17 @@ def test_pie_ccw_true():
plt.axis('equal')


@cleanup
def test_pathological_hexbin():
# issue #2863
with warnings.catch_warnings(record=True) as w:
mylist = [10] * 100
fig, ax = plt.subplots(1, 1)
ax.hexbin(mylist, mylist)
plt.show()
assert_equal(len(w), 0)


if __name__ == '__main__':
import nose
import sys
Expand Down