diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 108cda04865f..10bb27129856 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3068,9 +3068,8 @@ def _update_title_position(self, renderer): top = -np.inf for ax in axs: bb = None - xticklabel_top = any(tick.label2.get_visible() for tick in - [ax.xaxis.majorTicks[0], ax.xaxis.minorTicks[0]]) - if (xticklabel_top or ax.xaxis.get_label_position() == 'top'): + if (ax.xaxis.get_ticks_position() in ['top', 'unknown'] or + ax.xaxis.get_label_position() == 'top'): bb = ax.xaxis.get_tightbbox(renderer) if bb is None: # Extent of the outline for colorbars, of the axes otherwise. diff --git a/lib/matplotlib/tests/baseline_images/test_polar/polar_title_position.png b/lib/matplotlib/tests/baseline_images/test_polar/polar_title_position.png new file mode 100644 index 000000000000..4a8786b1f892 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_polar/polar_title_position.png differ diff --git a/lib/matplotlib/tests/test_polar.py b/lib/matplotlib/tests/test_polar.py index ee38c88a123f..ff2ad6433e6b 100644 --- a/lib/matplotlib/tests/test_polar.py +++ b/lib/matplotlib/tests/test_polar.py @@ -220,6 +220,13 @@ def test_polar_rlabel_position(): ax.tick_params(rotation='auto') +@image_comparison(['polar_title_position.png'], style='mpl20') +def test_polar_title_position(): + fig = plt.figure() + ax = fig.add_subplot(projection='polar') + ax.set_title('foo') + + @image_comparison(['polar_theta_wedge'], style='default') def test_polar_theta_limits(): r = np.arange(0, 3.0, 0.01)