Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b47ccba

Browse files
committed
ENH: Allow offsetting PolarAxes' zero location.
Let the user specify an arbitrary zero location with reference to the usual cardinal points. This can be a bit more intuitive than requiring the offset in radians.
1 parent 202f40f commit b47ccba

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

lib/matplotlib/projections/polar.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,18 @@ def get_theta_offset(self):
694694
"""
695695
return self._theta_offset.get_matrix()[0, 2]
696696

697-
def set_theta_zero_location(self, loc):
697+
def set_theta_zero_location(self, loc, offset=0.0):
698698
"""
699699
Sets the location of theta's zero. (Calls set_theta_offset
700700
with the correct value in radians under the hood.)
701701
702-
May be one of "N", "NW", "W", "SW", "S", "SE", "E", or "NE".
702+
loc : str
703+
May be one of "N", "NW", "W", "SW", "S", "SE", "E", or "NE".
704+
705+
offset : float, optional
706+
An offset in degrees to apply from the specified `loc`. **Note:**
707+
this offset is *always* applied counter-clockwise regardless of
708+
the direction setting.
703709
"""
704710
mapping = {
705711
'N': np.pi * 0.5,
@@ -710,7 +716,7 @@ def set_theta_zero_location(self, loc):
710716
'SE': np.pi * 1.75,
711717
'E': 0,
712718
'NE': np.pi * 0.25 }
713-
return self.set_theta_offset(mapping[loc])
719+
return self.set_theta_offset(mapping[loc] + np.deg2rad(offset))
714720

715721
def set_theta_direction(self, direction):
716722
"""

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,15 +649,15 @@ def test_polar_rorigin():
649649
ax.set_rorigin(0.0)
650650

651651

652-
@image_comparison(baseline_images=['polar_theta_position'])
652+
@image_comparison(baseline_images=['polar_theta_position'], style='default')
653653
def test_polar_theta_position():
654654
r = np.arange(0, 3.0, 0.01)
655655
theta = 2*np.pi*r
656656

657657
fig = plt.figure()
658658
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)
659659
ax.plot(theta, r)
660-
ax.set_theta_zero_location("NW")
660+
ax.set_theta_zero_location("NW", 30)
661661
ax.set_theta_direction('clockwise')
662662

663663

0 commit comments

Comments
 (0)