glue-viz/bermuda — pull request #12 by astrofrog (2014-08-10 08:44:46+00:00)
Title: Added property to return Matplotlib transformation for bounding box (Alternative to #10)

This is a more sophisticated alternative to #10 - it does the rotation in the frame of reference of the figure, thereby preserving right angles. Here's a script to use it:

```
import numpy as np
from mpl_shapes.bbox import BBox

b = BBox(center=(4, 5), width=2, height=1.5, theta=30.)

import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle, Circle

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

# Draw bounding box itself
r = Rectangle((0,0),width=1,height=1,
transform=b.get_transform(ax),
edgecolor='0.8', facecolor='none')
ax.add_patch(r)

# Draw a 'circle' inside the bounding box (actually an ellipse)
c = Circle((0.5,0.5), radius=0.5,
transform=b.get_transform(ax),
edgecolor='red', facecolor='none')
ax.add_patch(c)

ax.set_xlim(0., 10.)
ax.set_ylim(0., 10.)

plt.show()
fig.savefig('ellipse.png')
```

It does not use the existing ``Affine2D`` transform because it needs to be able to use the latest bounding box and axes parameter. The time to do a transformation is 0.1ms, still plenty fast enough for interactive use.

You can also run the above script interactively and resize the window and the rotation should be preserved.

However, this does raise an interesting issue, which is that if one is using the shape to select points, by doing the rotation in the frame of reference of the figure, we are actually changing the shape in the frame of reference of the axes so this means any selection would need to be updated (although not if the selection is done and the shape disappears, glue-style)

@ChrisBeaumont - what do you think would be the most natural behavior?