8000 Fix title position for polar plots · matplotlib/matplotlib@604e2d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 604e2d8

Browse files
committed
Fix title position for polar plots
1 parent c2d502d commit 604e2d8

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,9 +3068,8 @@ def _update_title_position(self, renderer):
30683068
top = -np.inf
30693069
for ax in axs:
30703070
bb = None
3071-
xticklabel_top = any(tick.label2.get_visible() for tick in
3072-
[ax.xaxis.majorTicks[0], ax.xaxis.minorTicks[0]])
3073-
if (xticklabel_top or ax.xaxis.get_label_position() == 'top'):
3071+
if (ax.xaxis.get_ticks_position() in ['top', 'unknown'] or
3072+
ax.xaxis.get_label_position() == 'top'):
30743073
bb = ax.xaxis.get_tightbbox(renderer)
30753074
if bb is None:
30763075
# Extent of the outline for colorbars, of the axes otherwise.

lib/matplotlib/tests/test_polar.py

Lines changed: 15 additions & 0 deletions
< BB54 div data-testid="addition diffstat" class="DiffSquares-module__diffSquare--h5kjy DiffSquares-module__addition--jeNtt">
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ def test_polar_rlabel_position():
220220
ax.tick_params(rotation='auto')
221221

222222

223+
@mpl.style.context('default')
224+
def test_polar_title_position():
225+
fig = plt.figure()
226+
ax = fig.add_subplot(projection='polar')
227+
228+
t = ax.set_title('foo')
229+
fig.draw_without_rendering()
230+
default_position = t.get_position()
231+
232+
# With no x/theta tick labels, the title should be lower
233+
ax.tick_params(labelbottom=False, labeltop=False)
234+
fig.draw_without_rendering()
235+
assert t.get_position()[1] < default_position[1]
236+
237+
223238
@image_comparison(['polar_theta_wedge'], style='default')
224239
def test_polar_theta_limits():
225240
r = np.arange(0, 3.0, 0.01)

0 commit comments

Comments
 (0)
0