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

Skip to content

Commit 4034b85

Browse files
jklymakMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR matplotlib#10792: Fixed not being able to set vertical/horizontal alignments in polar graphs
1 parent beef8ba commit 4034b85

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

lib/matplotlib/projections/polar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,8 @@ def update_position(self, loc):
635635
text_angle = user_angle
636636
if self.label1On:
637637
if full:
638-
ha = 'left'
639-
va = 'bottom'
638+
ha = self.label1.get_ha()
639+
va = self.label1.get_va()
640640
else:
641641
ha, va = self._determine_anchor(mode, angle, direction > 0)
642642
self.label1.set_ha(ha)

lib/matplotlib/tests/test_axes.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,38 @@ def test_polar_coord_annotations():
456456
ax.set_ylim(-20, 20)
457457

458458

459+
@image_comparison(baseline_images=['polar_alignment'], extensions=['png'])
460+
def test_polar_alignment():
461+
'''
462+
Test that changing the vertical/horizontal alignment of a polar graph
463+
works as expected '''
464+
ranges = [(0, 5), (0, 5)]
465+
466+
angles = np.arange(0, 360, 90)
467+
468+
levels = 5
469+
470+
fig = plt.figure()
471+
472+
figureSize = [0.1, 0.1, 0.8, 0.8]
473+
474+
horizontal = fig.add_axes(figureSize, polar=True, label='horizontal')
475+
vertical = fig.add_axes(figureSize, polar=True, label='vertical')
476+
477+
axes = [horizontal, vertical]
478+
479+
horizontal.set_thetagrids(angles)
480+
481+
vertical.patch.set_visible(False)
482+
483+
for i in range(2):
484+
grid = np.linspace(*ranges[i], num=levels)
485+
gridValues = [0, 0.2, 0.4, 0.6, 0.8, 1]
486+
axes[i].set_rgrids(gridValues, angle=angles[i],
487+
horizontalalignment='left',
488+
verticalalignment='top')
489+
490+
459491
@image_comparison(baseline_images=['fill_units'], extensions=['png'],
460492
savefig_kwarg={'dpi': 60})
461493
def test_fill_units():

0 commit comments

Comments
 (0)