Add angle kwarg to patches.Rectangle #1405

Merged
merged 5 commits into from Nov 13, 2012

Conversation

Projects
None yet
4 participants
@dmcdougall
Member

dmcdougall commented Oct 15, 2012

Allows rotation of a rectangle upon instantiation.

Addresses #987.
The old attempt was #1156.

@dmcdougall

This comment has been minimized.

Show comment Hide comment
@dmcdougall

dmcdougall Oct 15, 2012

Member

Here's an example:

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
r = Rectangle((0.5, 1.0), 2, 1, angle=45.0)
ax.add_patch(r)
ax.set_xlim(0, 3)
ax.set_ylim(0, 3)
ax.set_aspect('equal')
fig.savefig('rect.pdf')
Member

dmcdougall commented Oct 15, 2012

Here's an example:

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
r = Rectangle((0.5, 1.0), 2, 1, angle=45.0)
ax.add_patch(r)
ax.set_xlim(0, 3)
ax.set_ylim(0, 3)
ax.set_aspect('equal')
fig.savefig('rect.pdf')
@wkerzendorf

This comment has been minimized.

Show comment Hide comment
@wkerzendorf

wkerzendorf Oct 15, 2012

@dmcdougall Thanks!!

@dmcdougall Thanks!!

@pelson

This comment has been minimized.

Show comment Hide comment
@pelson

pelson Oct 16, 2012

Member

Nice solution to the problem. 👍

Member

pelson commented Oct 16, 2012

Nice solution to the problem. 👍

@wkerzendorf

This comment has been minimized.

Show comment Hide comment
@wkerzendorf

wkerzendorf Nov 4, 2012

When will this be merged? It's really useful to me.

When will this be merged? It's really useful to me.

@dmcdougall

This comment has been minimized.

Show comment Hide comment
@dmcdougall

dmcdougall Nov 4, 2012

Member

I should add an entry to api_changes or whats_new (one of the other devs should advise me on this). It may be the case we are able to extend this for other artists, too. That should be done in a different pull request, though. This PR was only meant to satisfy the feature request in #987.

Member

dmcdougall commented Nov 4, 2012

I should add an entry to api_changes or whats_new (one of the other devs should advise me on this). It may be the case we are able to extend this for other artists, too. That should be done in a different pull request, though. This PR was only meant to satisfy the feature request in #987.

@WeatherGod

This comment has been minimized.

Show comment Hide comment
@WeatherGod

WeatherGod Nov 4, 2012

Member

On Sunday, November 4, 2012, Damon McDougall wrote:

I should add an entry to api_changes or whats_new (one of the other devs
should advise me on this). It may be the case we are able to extend this
for other artists, too. That should be done in a different pull request,
though. This PR was only meant to satisfy the feature request in #987#987
.

It should go into "what's new" because it doesn't require any changes to
existing code.

Member

WeatherGod commented Nov 4, 2012

On Sunday, November 4, 2012, Damon McDougall wrote:

I should add an entry to api_changes or whats_new (one of the other devs
should advise me on this). It may be the case we are able to extend this
for other artists, too. That should be done in a different pull request,
though. This PR was only meant to satisfy the feature request in #987#987
.

It should go into "what's new" because it doesn't require any changes to
existing code.

@dmcdougall

This comment has been minimized.

Show comment Hide comment
@dmcdougall

dmcdougall Nov 4, 2012

Member

Added a note in whats_new and added a test, too. Go me. When my friend Travis goes green, I consider this ready to merge. Others should review the code for any heinous style issues or hidden treasures.

Member

dmcdougall commented Nov 4, 2012

Added a note in whats_new and added a test, too. Go me. When my friend Travis goes green, I consider this ready to merge. Others should review the code for any heinous style issues or hidden treasures.

@WeatherGod

View changes

doc/users/whats_new.rst
@@ -20,6 +20,11 @@ revision, see the :ref:`github-stats`.
new in matplotlib-1.3
=====================
+Initialize a rotated rectangle
+------------------------------
+Damon McDougall extended the `~matplotlib.patches.Rectangle` constructor to

This comment has been minimized.

Show comment Hide comment
@WeatherGod

WeatherGod Nov 5, 2012

Member

should be :class:~matplotlib.patches.Rectangle``

@WeatherGod

WeatherGod Nov 5, 2012

Member

should be :class:~matplotlib.patches.Rectangle``

This comment has been minimized.

Show comment Hide comment
@dmcdougall

dmcdougall Nov 5, 2012

Member

Thanks.

@dmcdougall

dmcdougall Nov 5, 2012

Member

Thanks.

@WeatherGod

View changes

lib/matplotlib/patches.py
@@ -574,7 +578,10 @@ def _update_patch_transform(self):
width = self.convert_xunits(self._width)
height = self.convert_yunits(self._height)
bbox = transforms.Bbox.from_bounds(x, y, width, height)
+ rot_trans = transforms.Affine2D()
+ rot_trans.translate(-x, -y).rotate_deg(self._angle).translate(x, y)
self._rect_transform = transforms.BboxTransformTo(bbox)

This comment has been minimized.

Show comment Hide comment
@WeatherGod

WeatherGod Nov 5, 2012

Member

Why the translation?

@WeatherGod

WeatherGod Nov 5, 2012

Member

Why the translation?

This comment has been minimized.

Show comment Hide comment
@dmcdougall

dmcdougall Nov 5, 2012

Member

Because I didn't know rotate_deg_around existed. I will push an update to use that instead.

@dmcdougall

dmcdougall Nov 5, 2012

Member

Because I didn't know rotate_deg_around existed. I will push an update to use that instead.

@wkerzendorf

This comment has been minimized.

Show comment Hide comment
@wkerzendorf

wkerzendorf Nov 12, 2012

@dmcdougall How's your friend Travis going?

@dmcdougall How's your friend Travis going?

@dmcdougall

This comment has been minimized.

Show comment Hide comment
@dmcdougall

dmcdougall Nov 13, 2012

Member

@wkerzendorf He gave this PR the all-clear. I'm just waiting on some of the other devs to give feedback and merge it. I am against merging my own pull requests unless they're trivial changes.

Member

dmcdougall commented Nov 13, 2012

@wkerzendorf He gave this PR the all-clear. I'm just waiting on some of the other devs to give feedback and merge it. I am against merging my own pull requests unless they're trivial changes.

pelson added a commit that referenced this pull request Nov 13, 2012

Merge pull request #1405 from dmcdougall/rect_angle_kwarg
Add angle kwarg to patches.Rectangle

@pelson pelson merged commit 17e1cf8 into matplotlib:master Nov 13, 2012

1 check passed

default The Travis build passed
Details
@pelson

This comment has been minimized.

Show comment Hide comment
@pelson

pelson Nov 13, 2012

Member

Thanks @dmcdougall (and @wkerzendorf for the nudging 😉 ). Merged.

Member

pelson commented Nov 13, 2012

Thanks @dmcdougall (and @wkerzendorf for the nudging 😉 ). Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment