From c91ca7b900a7c61040f84ee3c3755bda3d4a0ad0 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 26 Jan 2019 22:44:00 +0100 Subject: [PATCH] Simplify some calculations in polar.py. (For the second modifications to RadialTick: the angle/tick_angle calculations are moved outside of the if block to not inherit the incorrect text_angle from the code above, even though in practice it didn't really matter as label2 (to which the angle is applied) is set to invisible in the other side of the if block.) --- lib/matplotlib/projections/polar.py | 40 ++++++----------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index 8fe76e9bf59c..6bfe50125994 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -598,24 +598,13 @@ def update_position(self, loc): angle = (axes.get_rlabel_position() * direction + offset) % 360 - 90 tick_angle = 0 - if angle > 90: - text_angle = angle - 180 - elif angle < -90: - text_angle = angle + 180 - else: - text_angle = angle else: angle = (thetamin * direction + offset) % 360 - 90 if direction > 0: tick_angle = np.deg2rad(angle) else: tick_angle = np.deg2rad(angle + 180) - if angle > 90: - text_angle = angle - 180 - elif angle < -90: - text_angle = angle + 180 - else: - text_angle = angle + text_angle = (angle + 90) % 180 - 90 # between -90 and +90. mode, user_angle = self._labelrotation if mode == 'auto': text_angle += user_angle @@ -646,18 +635,12 @@ def update_position(self, loc): if full: self.label2.set_visible(False) self.tick2line.set_visible(False) + angle = (thetamax * direction + offset) % 360 - 90 + if direction > 0: + tick_angle = np.deg2rad(angle) else: - angle = (thetamax * direction + offset) % 360 - 90 - if direction > 0: - tick_angle = np.deg2rad(angle) - else: - tick_angle = np.deg2rad(angle + 180) - if angle > 90: - text_angle = angle - 180 - elif angle < -90: - text_angle = angle + 180 - else: - text_angle = angle + tick_angle = np.deg2rad(angle + 180) + text_angle = (angle + 90) % 180 - 90 # between -90 and +90. mode, user_angle = self._labelrotation if mode == 'auto': text_angle += user_angle @@ -792,15 +775,8 @@ def get_points(self): # Ensure equal aspect ratio. w, h = self._points[1] - self._points[0] - if h < w: - deltah = (w - h) / 2.0 - deltaw = 0.0 - elif w < h: - deltah = 0.0 - deltaw = (h - w) / 2.0 - else: - deltah = 0.0 - deltaw = 0.0 + deltah = max(w - h, 0) / 2 + deltaw = max(h - w, 0) / 2 self._points += np.array([[-deltaw, -deltah], [deltaw, deltah]]) self._invalid = 0