Skip to content

Recompute Wedge path after change of attributes. #1635

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
Jan 16, 2013
Merged
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
39 changes: 32 additions & 7 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,22 +878,26 @@ def __init__(self, center, r, theta1, theta2, width=None, **kwargs):
self.center = center
self.r, self.width = r, width
self.theta1, self.theta2 = theta1, theta2
self._patch_transform = transforms.IdentityTransform()
self._recompute_path()

def _recompute_path(self):
# Inner and outer rings are connected unless the annulus is complete
if abs((theta2 - theta1) - 360) <= 1e-12:
if abs((self.theta2 - self.theta1) - 360) <= 1e-12:
theta1, theta2 = 0, 360
connector = Path.MOVETO
else:
theta1, theta2 = self.theta1, self.theta2
connector = Path.LINETO

# Form the outer ring
arc = Path.arc(theta1, theta2)

if width is not None:
# Partial annulus needs to draw the outter ring
if self.width is not None:
# Partial annulus needs to draw the outer ring
# followed by a reversed and scaled inner ring
v1 = arc.vertices
v2 = arc.vertices[::-1] * float(r - width) / r
v2 = arc.vertices[::-1] * float(self.r - self.width) / self.r
v = np.vstack([v1, v2, v1[0, :], (0, 0)])
c = np.hstack([arc.codes, arc.codes, connector, Path.CLOSEPOLY])
c[len(arc.codes)] = connector
Expand All @@ -903,12 +907,33 @@ def __init__(self, center, r, theta1, theta2, width=None, **kwargs):
c = np.hstack([arc.codes, [connector, connector, Path.CLOSEPOLY]])

# Shift and scale the wedge to the final location.
v *= r
v += np.asarray(center)
v *= self.r
v += np.asarray(self.center)
self._path = Path(v, c)
self._patch_transform = transforms.IdentityTransform()

def set_center(self, center):
self._path = None
self.center = center

def set_radius(self, radius):
self._path = None
self.radius = radius

def set_theta1(self, theta1):
self._path = None
self.theta1 = theta1

def set_theta2(self, theta2):
self._path = None
self.theta2 = theta2

def set_width(self, width):
self._path = None
self.width = width

def get_path(self):
if self._path is None:
self._recompute_path()
return self._path


Expand Down