diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index 6c7fd01e12e7..fe9f3e536171 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -328,8 +328,9 @@ def _update_padding(self, pad, angle): def update_position(self, loc): super(ThetaTick, self).update_position(loc) axes = self.axes - angle = (loc * axes.get_theta_direction() + - axes.get_theta_offset() - np.pi / 2) + angle = loc * axes.get_theta_direction() + axes.get_theta_offset() + text_angle = np.rad2deg(angle) % 360 - 90 + angle -= np.pi / 2 if self.tick1On: marker = self.tick1line.get_marker() @@ -354,17 +355,17 @@ def update_position(self, loc): mode, user_angle = self._labelrotation if mode == 'default': - angle = 0 + text_angle = user_angle else: - if angle > np.pi / 2: - angle -= np.pi - elif angle < -np.pi / 2: - angle += np.pi - angle = np.rad2deg(angle) + user_angle + if text_angle > 90: + text_angle -= 180 + elif text_angle < -90: + text_angle += 180 + text_angle += user_angle if self.label1On: - self.label1.set_rotation(angle) + self.label1.set_rotation(text_angle) if self.label2On: - self.label2.set_rotation(angle) + self.label2.set_rotation(text_angle) # This extra padding helps preserve the look from previous releases but # is also needed because labels are anchored to their center. @@ -542,17 +543,59 @@ def _get_text2(self): t.set_rotation_mode('anchor') return t - def _determine_anchor(self, angle, start): - if start: - if -90 <= angle <= 90: - return 'left', 'center' + def _determine_anchor(self, mode, angle, start): + # Note: angle is the (spine angle - 90) because it's used for the tick + # & text setup, so all numbers below are -90 from (normed) spine angle. + if mode == 'auto': + if start: + if -90 <= angle <= 90: + return 'left', 'center' + else: + return 'right', 'center' else: - return 'right', 'center' + if -90 <= angle <= 90: + return 'right', 'center' + else: + return 'left', 'center' else: - if -90 <= angle <= 90: - return 'right', 'center' + if start: + if angle < -68.5: + return 'center', 'top' + elif angle < -23.5: + return 'left', 'top' + elif angle < 22.5: + return 'left', 'center' + elif angle < 67.5: + return 'left', 'bottom' + elif angle < 112.5: + return 'center', 'bottom' + elif angle < 157.5: + return 'right', 'bottom' + elif angle < 202.5: + return 'right', 'center' + elif angle < 247.5: + return 'right', 'top' + else: + return 'center', 'top' else: - return 'left', 'center' + if angle < -68.5: + return 'center', 'bottom' + elif angle < -23.5: + return 'right', 'bottom' + elif angle < 22.5: + return 'right', 'center' + elif angle < 67.5: + return 'right', 'top' + elif angle < 112.5: + return 'center', 'top' + elif angle < 157.5: + return 'left', 'top' + elif angle < 202.5: + return 'left', 'center' + elif angle < 247.5: + return 'left', 'bottom' + else: + return 'center', 'bottom' def update_position(self, loc): super(RadialTick, self).update_position(loc) @@ -565,7 +608,8 @@ def update_position(self, loc): full = _is_full_circle_deg(thetamin, thetamax) if full: - angle = axes.get_rlabel_position() * direction + offset - 90 + angle = (axes.get_rlabel_position() * direction + + offset) % 360 - 90 tick_angle = 0 if angle > 90: text_angle = angle - 180 @@ -574,7 +618,7 @@ def update_position(self, loc): else: text_angle = angle else: - angle = thetamin * direction + offset - 90 + angle = (thetamin * direction + offset) % 360 - 90 if direction > 0: tick_angle = np.deg2rad(angle) else: @@ -595,7 +639,7 @@ def update_position(self, loc): ha = 'left' va = 'bottom' else: - ha, va = self._determine_anchor(angle, True) + ha, va = self._determine_anchor(mode, angle, direction > 0) self.label1.set_ha(ha) self.label1.set_va(va) self.label1.set_rotation(text_angle) @@ -622,7 +666,7 @@ def update_position(self, loc): self.label2On = False self.tick2On = False else: - angle = thetamax * direction + offset - 90 + angle = (thetamax * direction + offset) % 360 - 90 if direction > 0: tick_angle = np.deg2rad(angle) else: @@ -639,7 +683,7 @@ def update_position(self, loc): else: text_angle = user_angle if self.label2On: - ha, va = self._determine_anchor(angle, False) + ha, va = self._determine_anchor(mode, angle, direction < 0) self.label2.set_ha(ha) self.label2.set_va(va) self.label2.set_rotation(text_angle) @@ -932,16 +976,10 @@ def get_xaxis_transform(self, which='grid'): return self._xaxis_transform def get_xaxis_text1_transform(self, pad): - if _is_full_circle_rad(*self._realViewLim.intervalx): - return self._xaxis_text_transform, 'center', 'center' - else: - return self._xaxis_text_transform, 'bottom', 'center' + return self._xaxis_text_transform, 'center', 'center' def get_xaxis_text2_transform(self, pad): - if _is_full_circle_rad(*self._realViewLim.intervalx): - return self._xaxis_text_transform, 'center', 'center' - else: - return self._xaxis_text_transform, 'top', 'center' + return self._xaxis_text_transform, 'center', 'center' def get_yaxis_transform(self, which='grid'): if which in ('tick1', 'tick2'): @@ -1116,10 +1154,6 @@ def set_theta_direction(self, direction): raise ValueError( "direction must be 1, -1, clockwise or counterclockwise") self._direction.invalidate() - # FIXME: Why is this needed? Even though the tick label gets - # re-created, the alignment is not correctly updated without a reset. - self.yaxis.reset_ticks() - self.yaxis.set_clip_path(self.patch) def get_theta_direction(self): """ @@ -1176,8 +1210,6 @@ def set_rlabel_position(self, value): The angular position of the radius labels in degrees. """ self._r_label_position.clear().translate(np.deg2rad(value), 0.0) - self.yaxis.reset_ticks() - self.yaxis.set_clip_path(self.patch) def set_yscale(self, *args, **kwargs): Axes.set_yscale(self, *args, **kwargs) diff --git a/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.pdf b/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.pdf index 64ccc93fdae5..87539484bbc5 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.pdf and b/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.png b/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.png index 91986a07f187..262ac6cc6363 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.png and b/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.svg b/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.svg index 26bc1035b646..d0c9ffd8f920 100644 --- a/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.svg +++ b/lib/matplotlib/tests/baseline_images/test_axes/polar_theta_wedge.svg @@ -32,7 +32,7 @@ z - @@ -40,20 +40,20 @@ L 154.714339 91.0661 +" id="m4267810ffa" style="stroke:#000000;stroke-width:0.8;"/> - + +" id="m2959245d8b" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -137,7 +137,7 @@ z - @@ -145,20 +145,20 @@ L 141.714347 68.549453 +" id="maa0cf13df2" style="stroke:#000000;stroke-width:0.8;"/> - + +" id="mcc2db099b7" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -193,7 +193,7 @@ z - +" id="m534c638152" style="stroke:#000000;stroke-width:0.8;"/> - + +" id="mdfd80e9554" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -235,7 +235,7 @@ L -2.681156 -2.249757 - - + - + @@ -273,7 +273,7 @@ L 115.814731 79.191015 - - @@ -565,20 +565,20 @@ L 259.638801 77.22034 +" id="md666185658" style="stroke:#000000;stroke-width:0.8;"/> - + +" id="mc057861159" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -618,7 +618,7 @@ z - @@ -626,20 +626,20 @@ L 225.551059 68.086557 +" id="mb60c3d17ac" style="stroke:#000000;stroke-width:0.8;"/> - + +" id="mc01e554bb2" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -671,7 +671,7 @@ z - - + - + @@ -707,7 +707,7 @@ L 231.34739 107.984257 - - + - + @@ -762,7 +762,7 @@ L 211.898434 91.664645 - - - + - + @@ -1025,18 +1025,18 @@ L 347.838094 56.400227 - - + - + @@ -1053,7 +1053,7 @@ L 319.776597 105.004167 - - + +" id="m6814606db8" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -1097,7 +1097,7 @@ L 2.681156 2.249757 - - + - + @@ -1162,7 +1162,7 @@ L 338.81056 110.814764 - - - + - + @@ -1427,18 +1427,18 @@ L 464.349724 52.465792 - - + - + @@ -1453,7 +1453,7 @@ L 436.765818 100.242519 - @@ -1461,20 +1461,20 @@ L 488.606605 119.111022 +" id="m4c5195b373" style="stroke:#000000;stroke-width:0.8;"/> - + +" id="m29dd35bcdc" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -1525,7 +1525,7 @@ z - - + - + @@ -1568,7 +1568,7 @@ L 471.856302 88.979053 - - + - + @@ -1657,7 +1657,7 @@ L 488.629733 103.053632 - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + - + - + - + - + - + @@ -1897,23 +2327,23 @@ L 228.216492 146.094595 - - - + + - + - + - + - + - + @@ -1924,47 +2354,47 @@ L 208.299348 162.807062 - - - - + + + - + +" id="m35f86462da" style="stroke:#000000;stroke-width:0.8;"/> - + - + - + - + - + - - - + + - + - + - + - + - + - + @@ -2001,8 +2431,8 @@ L 228.168407 179.479182 - - + - + - + - + - - + + - - - - + + + - + +" id="ma9fd134468" style="stroke:#000000;stroke-width:0.8;"/> - + - + +" id="m448307176d" style="stroke:#000000;stroke-width:0.8;"/> - + - + @@ -2320,23 +2750,23 @@ L 3.031089 1.75 - - - + + - + - + - + - + - + @@ -2347,10 +2777,10 @@ L 335.399764 193.224877 - - - - + + + - + - + - + - + - + - + - - - + + - + - + - + - + - + - + @@ -2440,8 +2870,8 @@ L 357.094211 199.847653 - - + - + - + - + - - + + - - - - + + + - + - + - + - + - + @@ -2702,23 +3132,23 @@ L 439.93461 186.527915 - - - + + - + - + - + - + - + @@ -2729,10 +3159,10 @@ L 492.672974 205.72311 - - - - + + + - + - + - + - + - + - + - - - + + - + - + - + - + - + - + @@ -2835,8 +3265,8 @@ L 492.696503 189.3877 - - + - + - + - + - - - + + - - - - + + + - + - + - + - + - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + - + - + - + - + - + - - - - - + + + + + - - - - + + + - + - + - + - + - + - + - + - + - + - + - - - + + - + - + - + - + - + - + - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - - + - - - + + - - - - + + + - + + + + - + - + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -3499,349 +5610,765 @@ L 434.817025 254.620189 - - - + + - + - + - + - + + + + - + - - - - - + + + + + - - - - + + + - + - + - - - - + - + - + - + - + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - - + - - + - - + - - + - - + + - - - - + + + - + - + - + - + - + @@ -3879,23 +6406,23 @@ L 478.635682 377.001058 - - - + + - + - + - + - + - + @@ -3906,42 +6433,42 @@ L 498.552826 360.28859 - - - - + + + - + - + - + - + - + - + - - - + + - + - + - + - + - + - + @@ -3978,8 +6505,8 @@ L 478.683767 343.61647 - - + - + - + - + @@ -4246,7 +6773,7 @@ L 498.552826 360.28859 - + - + - + - + - + + + + - + - + - + + + + + + + - + - + + + + + + + + + +