Skip to content

Move float() casting in Rectangle patch #8938

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 6 commits into from
Jul 26, 2017
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
8 changes: 4 additions & 4 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/testing/jpl_units/UnitDbl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
2 changes: 2 additions & 0 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down