From 4ed681ad31014251ab4f5362fdbe4bd61cd57647 Mon Sep 17 00:00:00 2001 From: MuhammadFarooq1234 Date: Thu, 5 Mar 2020 20:27:51 -0500 Subject: [PATCH 1/2] correct xtick.alignment validation paramters --- lib/matplotlib/rcsetup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 9eefcccdcbc7..82f4acd5accc 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -1342,7 +1342,7 @@ def _convert_validator_spec(key, conv): 'xtick.labelsize': ['medium', validate_fontsize], 'xtick.direction': ['out', validate_string], # direction of xticks 'xtick.alignment': ['center', - ['center', 'top', 'bottom', 'baseline', 'center_baseline']], + ['center', 'right', 'left']], 'ytick.left': [True, validate_bool], # draw ticks on the left side 'ytick.right': [False, validate_bool], # draw ticks on the right side From e923f7ac55b65c6cd959b85a548c57614b6792a4 Mon Sep 17 00:00:00 2001 From: MuhammadFarooq1234 Date: Sun, 8 Mar 2020 15:46:28 -0400 Subject: [PATCH 2/2] Add test cases for #16583 --- lib/matplotlib/tests/test_rcparams.py | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index d68e2a94f693..65e4568ea3e8 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -534,3 +534,48 @@ def test_backend_fallback_headful(tmpdir): # The actual backend will depend on what's installed, but at least tkagg is # present. assert backend.strip().lower() != "agg" + +# Test cases for Bug 16583 - matplotlibrc validates some parameters wrongly + +def test_xtickalign_validation_rcparams(): + with pytest.raises(ValueError): + mpl.rcParams['xtick.alignment'] = 'top' + +@check_figures_equal() +def test_left_xtick(fig_test, fig_ref): + labels = range(0, 100, 10) + + fig_test.subplots() + ax1 = fig_test.axes + ax1[0].set_xticklabels(labels, ha='left') + + mpl.rcParams['xtick.alignment'] = 'left' + fig_ref.subplots() + ax2 = fig_ref.axes + ax2[0].set_xticklabels(labels) + +@check_figures_equal() +def test_right_xtick(fig_test, fig_ref): + labels = range(0, 100, 10) + + fig_test.subplots() + ax1 = fig_test.axes + ax1[0].set_xticklabels(labels, ha='right') + + mpl.rcParams['xtick.alignment'] = 'right' + fig_ref.subplots() + ax2 = fig_ref.axes + ax2[0].set_xticklabels(labels) + +@check_figures_equal() +def test_center_xtick(fig_test, fig_ref): + labels = range(0, 100, 10) + + fig_test.subplots() + ax1 = fig_test.axes + ax1[0].set_xticklabels(labels, ha='center') + + mpl.rcParams['xtick.alignment'] = 'center' + fig_ref.subplots() + ax2 = fig_ref.axes + ax2[0].set_xticklabels(labels)