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 df52f01

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

File tree

Expand file treeCollapse file tree

6 files changed

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

6 files changed

+373
-41
lines changed

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+41-37Lines changed: 41 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,6 @@ 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-
20462019
# Get width and height in pixels we need to use
20472020
# `self.get_data_transform` rather than `self.get_transform`
20482021
# because we want the transform from dataspace to the
@@ -2051,12 +2024,12 @@ def theta_stretch(theta, scale):
20512024
# `self.get_transform()` goes from an idealized unit-radius
20522025
# space to screen space).
20532026
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)))
2027+
pwidth, pheight = (
2028+
data_to_screen_trans.transform((self._width, self._height)) -
2029+
data_to_screen_trans.transform((0, 0)))
20562030
inv_error = (1.0 / 1.89818e-6) * 0.5
20572031

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

20622035
def line_circle_intersect(x0, y0, x1, y1):
@@ -2110,10 +2083,11 @@ def segment_circle_intersect(x0, y0, x1, y1):
21102083
# arctan2 return [-pi, pi), the rest of our angles are in
21112084
# [0, 360], adjust as needed.
21122085
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)
2086+
thetas.update(
2087+
theta[(self._theta1 < theta) & (theta < self._theta2)])
2088+
thetas = sorted(thetas) + [self._theta2]
2089+
last_theta = self._theta1
2090+
theta1_rad = np.deg2rad(self._theta1)
21172091
inside = box_path.contains_point(
21182092
(np.cos(theta1_rad), np.sin(theta1_rad))
21192093
)
@@ -2132,6 +2106,36 @@ def segment_circle_intersect(x0, y0, x1, y1):
21322106
# restore original path
21332107
self._path = path_original
21342108

2109+
def _theta_stretch(self):
2110+
# If the width and height of ellipse are not equal, take into account
2111+
# stretching when calculating angles to draw between
2112+
def theta_stretch(theta, scale):
2113+
theta = np.deg2rad(theta)
2114+
x = np.cos(theta)
2115+
y = np.sin(theta)
2116+
stheta = np.rad2deg(np.arctan2(scale * y, x))
2117+
# arctan2 has the range [-pi, pi], we expect [0, 2*pi]
2118+
return (stheta + 360) % 360
2119+
2120+
width = self.convert_xunits(self.width)
2121+
height = self.convert_yunits(self.height)
2122+
if (
2123+
# if we need to stretch the angles because we are distorted
2124+
width != height
2125+
# and we are not doing a full circle.
2126+
#
2127+
# 0 and 360 do not exactly round-trip through the angle
2128+
# stretching (due to both float precision limitations and
2129+
# the difference between the range of arctan2 [-pi, pi] and
2130+
# this method [0, 360]) so avoid doing it if we don't have to.
2131+
and not (self.theta1 != self.theta2 and
2132+
self.theta1 % 360 == self.theta2 % 360)
2133+
):
2134+
theta1 = theta_stretch(self.theta1, width / height)
2135+
theta2 = theta_stretch(self.theta2, width / height)
2136+
return theta1, theta2, width, height
2137+
return self.theta1, self.theta2, width, height
2138+
21352139

21362140
def bbox_artist(artist, renderer, props=None, fill=True):
21372141
"""
Loading

0 commit comments

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