Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug fix 16583 - resetup.py param xtick.alignment updated to properly validate values #16712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)