Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6f4ae90

Browse filesBrowse files
committed
Set correct path for Arc
1 parent 65cbdef commit 6f4ae90
Copy full SHA for 6f4ae90

File tree

Expand file treeCollapse file tree

6 files changed

+382
-41
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+382
-41
lines changed

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+50-37Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,9 @@ def __init__(self, xy, width, height, angle=0.0,
19611961

19621962
self.theta1 = theta1
19631963
self.theta2 = theta2
1964+
self._theta1, self._theta2, self._width, self._height = \
1965+
self._theta_stretch()
1966+
self._path = Path.arc(self._theta1, self._theta2)
19641967

19651968
@artist.allow_rasterization
19661969
def draw(self, renderer):
@@ -2013,36 +2016,7 @@ def draw(self, renderer):
20132016

20142017
self._recompute_transform()
20152018

2016-
width = self.convert_xunits(self.width)
2017-
height = self.convert_yunits(self.height)
2018-
2019-
# If the width and height of ellipse are not equal, take into account
2020-
# stretching when calculating angles to draw between
2021-
def theta_stretch(theta, scale):
2022-
theta = np.deg2rad(theta)
2023-
x = np.cos(theta)
2024-
y = np.sin(theta)
2025-
stheta = np.rad2deg(np.arctan2(scale * y, x))
2026-
# arctan2 has the range [-pi, pi], we expect [0, 2*pi]
2027-
return (stheta + 360) % 360
2028-
2029-
theta1 = self.theta1
2030-
theta2 = self.theta2
2031-
2032-
if (
2033-
# if we need to stretch the angles because we are distorted
2034-
width != height
2035-
# and we are not doing a full circle.
2036-
#
2037-
# 0 and 360 do not exactly round-trip through the angle
2038-
# stretching (due to both float precision limitations and
2039-
# the difference between the range of arctan2 [-pi, pi] and
2040-
# this method [0, 360]) so avoid doing it if we don't have to.
2041-
and not (theta1 != theta2 and theta1 % 360 == theta2 % 360)
2042-
):
2043-
theta1 = theta_stretch(self.theta1, width / height)
2044-
theta2 = theta_stretch(self.theta2, width / height)
2045-
2019+
self._update_path()
20462020
# Get width and height in pixels we need to use
20472021
# `self.get_data_transform` rather than `self.get_transform`
20482022
# because we want the transform from dataspace to the
@@ -2051,12 +2025,12 @@ def theta_stretch(theta, scale):
20512025
# `self.get_transform()` goes from an idealized unit-radius
20522026
# space to screen space).
20532027
data_to_screen_trans = self.get_data_transform()
2054-
pwidth, pheight = (data_to_screen_trans.transform((width, height)) -
2055-
data_to_screen_trans.transform((0, 0)))
2028+
pwidth, pheight = (
2029+
data_to_screen_trans.transform((self._width, self._height)) -
2030+
data_to_screen_trans.transform((0, 0)))
20562031
inv_error = (1.0 / 1.89818e-6) * 0.5
20572032

20582033
if pwidth < inv_error and pheight < inv_error:
2059-
self._path = Path.arc(theta1, theta2)
20602034
return Patch.draw(self, renderer)
20612035

20622036
def line_circle_intersect(x0, y0, x1, y1):
@@ -2110,10 +2084,11 @@ def segment_circle_intersect(x0, y0, x1, y1):
21102084
# arctan2 return [-pi, pi), the rest of our angles are in
21112085
# [0, 360], adjust as needed.
21122086
theta = (np.rad2deg(np.arctan2(y, x)) + 360) % 360
2113-
thetas.update(theta[(theta1 < theta) & (theta < theta2)])
2114-
thetas = sorted(thetas) + [theta2]
2115-
last_theta = theta1
2116-
theta1_rad = np.deg2rad(theta1)
2087+
thetas.update(
2088+
theta[(self._theta1 < theta) & (theta < self._theta2)])
2089+
thetas = sorted(thetas) + [self._theta2]
2090+
last_theta = self._theta1
2091+
theta1_rad = np.deg2rad(self._theta1)
21172092
inside = box_path.contains_point(
21182093
(np.cos(theta1_rad), np.sin(theta1_rad))
21192094
)
@@ -2132,6 +2107,44 @@ def segment_circle_intersect(x0, y0, x1, y1):
21322107
# restore original path
21332108
self._path = path_original
21342109

2110+
def _update_path(self):
2111+
# Compute new values and update and set new _path if any value changed
2112+
stretched = self._theta_stretch()
2113+
if any(a != b for a, b in zip(stretched, (self._theta1, self._theta2,
2114+
self._width, self._height))):
2115+
self._theta1, self._theta2, self._width, self._height = stretched
2116+
self._path = Path.arc(self._theta1, self._theta2)
2117+
2118+
def _theta_stretch(self):
2119+
# If the width and height of ellipse are not equal, take into account
2120+
# stretching when calculating angles to draw between
2121+
def theta_stretch(theta, scale):
2122+
theta = np.deg2rad(theta)
2123+
x = np.cos(theta)
2124+
y = np.sin(theta)
2125+
stheta = np.rad2deg(np.arctan2(scale * y, x))
2126+
# arctan2 has the range [-pi, pi], we expect [0, 2*pi]
2127+
return (stheta + 360) % 360
2128+
2129+
width = self.convert_xunits(self.width)
2130+
height = self.convert_yunits(self.height)
2131+
if (
2132+
# if we need to stretch the angles because we are distorted
2133+
width != height
2134+
# and we are not doing a full circle.
2135+
#
2136+
# 0 and 360 do not exactly round-trip through the angle
2137+
# stretching (due to both float precision limitations and
2138+
# the difference between the range of arctan2 [-pi, pi] and
2139+
# this method [0, 360]) so avoid doing it if we don't have to.
2140+
and not (self.theta1 != self.theta2 and
2141+
self.theta1 % 360 == self.theta2 % 360)
2142+
):
2143+
theta1 = theta_stretch(self.theta1, width / height)
2144+
theta2 = theta_stretch(self.theta2, width / height)
2145+
return theta1, theta2, width, height
2146+
return self.theta1, self.theta2, width, height
2147+
21352148

21362149
def bbox_artist(artist, renderer, props=None, fill=True):
21372150
"""
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.