diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index 0ee03bc30785..62fc0f9ac60d 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -635,8 +635,8 @@ def update_position(self, loc): text_angle = user_angle if self.label1On: if full: - ha = 'left' - va = 'bottom' + ha = self.label1.get_ha() + va = self.label1.get_va() else: ha, va = self._determine_anchor(mode, angle, direction > 0) self.label1.set_ha(ha) diff --git a/lib/matplotlib/tests/baseline_images/test_axes/polar_alignment.png b/lib/matplotlib/tests/baseline_images/test_axes/polar_alignment.png new file mode 100644 index 000000000000..c6f745275e85 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/polar_alignment.png differ diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 77ec92b0123f..df6c6784da87 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -456,6 +456,38 @@ def test_polar_coord_annotations(): ax.set_ylim(-20, 20) +@image_comparison(baseline_images=['polar_alignment'], extensions=['png']) +def test_polar_alignment(): + ''' + Test that changing the vertical/horizontal alignment of a polar graph + works as expected ''' + ranges = [(0, 5), (0, 5)] + + angles = np.arange(0, 360, 90) + + levels = 5 + + fig = plt.figure() + + figureSize = [0.1, 0.1, 0.8, 0.8] + + horizontal = fig.add_axes(figureSize, polar=True, label='horizontal') + vertical = fig.add_axes(figureSize, polar=True, label='vertical') + + axes = [horizontal, vertical] + + horizontal.set_thetagrids(angles) + + vertical.patch.set_visible(False) + + for i in range(2): + grid = np.linspace(*ranges[i], num=levels) + gridValues = [0, 0.2, 0.4, 0.6, 0.8, 1] + axes[i].set_rgrids(gridValues, angle=angles[i], + horizontalalignment='left', + verticalalignment='top') + + @image_comparison(baseline_images=['fill_units'], extensions=['png'], savefig_kwarg={'dpi': 60}) def test_fill_units():