diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 26195999f622..6c1d5fa84a97 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -688,10 +688,10 @@ def __init__(self, xy, width, height, angle=0.0, **kwargs): Patch.__init__(self, **kwargs) - self._x = float(xy[0]) - self._y = float(xy[1]) - self._width = float(width) - self._height = float(height) + self._x = xy[0] + self._y = xy[1] + self._width = width + self._height = height self.angle = float(angle) # Note: This cannot be calculated until this is added to an Axes self._rect_transform = transforms.IdentityTransform() diff --git a/lib/matplotlib/testing/jpl_units/UnitDbl.py b/lib/matplotlib/testing/jpl_units/UnitDbl.py index 4eca2fb30951..20c89308dfd1 100644 --- a/lib/matplotlib/testing/jpl_units/UnitDbl.py +++ b/lib/matplotlib/testing/jpl_units/UnitDbl.py @@ -116,7 +116,10 @@ def __nonzero__( self ): = RETURN VALUE - Returns true if the value is non-zero. """ - return self._value.__nonzero__() + if six.PY3: + return self._value.__bool__() + else: + return self._value.__nonzero__() if six.PY3: __bool__ = __nonzero__ diff --git a/lib/matplotlib/tests/baseline_images/test_patches/units_rectangle.png b/lib/matplotlib/tests/baseline_images/test_patches/units_rectangle.png new file mode 100644 index 000000000000..651e1e2ef95a Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_patches/units_rectangle.png differ diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b58345a51184..09a75616db69 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4946,6 +4946,13 @@ def test_ls_ds_conflict(): plt.plot(range(32), linestyle='steps-pre:', drawstyle='steps-post') +def test_bar_uint8(): + xs = [0, 1, 2, 3] + b = plt.bar(np.array(xs, dtype=np.uint8), [2, 3, 4, 5]) + for (patch, x) in zip(b.patches, xs): + assert patch.xy[0] == x + + @image_comparison(baseline_images=['date_timezone_x'], extensions=['png']) def test_date_timezone_x(): # Tests issue 5575 diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index 3b55c284214b..44d8b3915bcf 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -351,3 +351,16 @@ def test_adding_rectangle_patch_with_polar_projection(): ) ) ax.set_rmax(2) + + +@image_comparison(baseline_images=['units_rectangle'], extensions=['png']) +def test_units_rectangle(): + import matplotlib.testing.jpl_units as U + U.register() + + p = mpatches.Rectangle((5*U.km, 6*U.km), 1*U.km, 2*U.km) + + fig, ax = plt.subplots() + ax.add_patch(p) + ax.set_xlim([4*U.km, 7*U.km]) + ax.set_ylim([5*U.km, 9*U.km]) diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index 824b65e50b4c..17b838b7c05e 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -1908,6 +1908,8 @@ def rotate_deg_around(self, x, y, degrees): calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate` and :meth:`scale`. """ + # Cast to float to avoid wraparound issues with uint8's + x, y = float(x), float(y) return self.translate(-x, -y).rotate_deg(degrees).translate(x, y) def translate(self, tx, ty):