From b1a35758667db446e06c3a779a532a0aeedb5b04 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 22 Mar 2019 16:13:32 -0700 Subject: [PATCH 1/3] FIX: make title move above ticklabels --- lib/matplotlib/axes/_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 95d534bf1507..044594209a0c 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2535,8 +2535,8 @@ def _update_title_position(self, renderer): top = 0 for ax in axs: try: - if (ax.xaxis.get_label_position() == 'top' - or ax.xaxis.get_ticks_position() == 'top'): + if (ax.xaxis.get_label_position() != 'bottom' + or ax.xaxis.get_ticks_position() != 'bottom'): bb = ax.xaxis.get_tightbbox(renderer) else: bb = ax.get_window_extent(renderer) From 873057c887116614489ab34b335df4aab7f494d7 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 22 Mar 2019 16:23:24 -0700 Subject: [PATCH 2/3] TST: add test for title behaviour --- lib/matplotlib/tests/test_axes.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index cf29daba9ae3..741a9c2b574a 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5723,6 +5723,16 @@ def test_title_xticks_top(): assert ax.title.get_position()[1] > 1.04 +def test_title_xticks_top_both(): + # Test that title moves if xticks on top of axes. + fig, ax = plt.subplots() + ax.tick_params(axis="x", bottom=True, top=True, + labelbottom=True, labeltop=True) + ax.set_title('xlabel top') + fig.canvas.draw() + assert ax.title.get_position()[1] > 1.04 + + def test_offset_label_color(): # Tests issue 6440 fig = plt.figure() From b4a1a97d590639daa6520339efa08aa3d2cad756 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sat, 23 Mar 2019 07:49:18 -0700 Subject: [PATCH 3/3] FIX: expand choices to top and unknown --- lib/matplotlib/axes/_base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 044594209a0c..a61be157e012 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2535,8 +2535,9 @@ def _update_title_position(self, renderer): top = 0 for ax in axs: try: - if (ax.xaxis.get_label_position() != 'bottom' - or ax.xaxis.get_ticks_position() != 'bottom'): + choices = ['top', 'unknown'] + if (ax.xaxis.get_label_position() == 'top' or + ax.xaxis.get_ticks_position() in choices): bb = ax.xaxis.get_tightbbox(renderer) else: bb = ax.get_window_extent(renderer)