Skip to content

FIX label vertical alignment can now be specified #8081

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

Merged
merged 3 commits into from
Feb 21, 2017
Merged
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
1 change: 1 addition & 0 deletions doc/users/dflt_style_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ values is a single line of python
See :ref:`customizing-with-matplotlibrc-files` for details about how to
persistently and selectively revert many of these changes.


.. contents:: Table of Contents
:depth: 2
:local:
Expand Down
23 changes: 13 additions & 10 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,12 @@ def get_xaxis_text1_transform(self, pad_points):
place axis elements in different locations.

"""
labels_align = matplotlib.rcParams["xtick.alignment"]

return (self.get_xaxis_transform(which='tick1') +
mtransforms.ScaledTranslation(0, -1 * pad_points / 72.0,
self.figure.dpi_scale_trans),
"top", "center")
"top", labels_align)

def get_xaxis_text2_transform(self, pad_points):
"""
Expand All @@ -757,10 +759,11 @@ def get_xaxis_text2_transform(self, pad_points):
place axis elements in different locations.

"""
labels_align = matplotlib.rcParams["xtick.alignment"]
return (self.get_xaxis_transform(which='tick2') +
mtransforms.ScaledTranslation(0, pad_points / 72.0,
self.figure.dpi_scale_trans),
"bottom", "center")
"bottom", labels_align)

def get_yaxis_transform(self, which='grid'):
"""
Expand Down Expand Up @@ -808,10 +811,11 @@ def get_yaxis_text1_transform(self, pad_points):
place axis elements in different locations.

"""
labels_align = matplotlib.rcParams["ytick.alignment"]
return (self.get_yaxis_transform(which='tick1') +
mtransforms.ScaledTranslation(-1 * pad_points / 72.0, 0,
self.figure.dpi_scale_trans),
"center_baseline", "right")
labels_align, "right")

def get_yaxis_text2_transform(self, pad_points):
"""
Expand All @@ -834,10 +838,12 @@ def get_yaxis_text2_transform(self, pad_points):
place axis elements in different locations.

"""
labels_align = matplotlib.rcParams["ytick.alignment"]

return (self.get_yaxis_transform(which='tick2') +
mtransforms.ScaledTranslation(pad_points / 72.0, 0,
self.figure.dpi_scale_trans),
"center_baseline", "left")
labels_align, "left")

def _update_transScale(self):
self.transScale.set(
Expand Down Expand Up @@ -2560,13 +2566,10 @@ def ticklabel_format(self, **kwargs):
raise ValueError("scilimits must be a sequence of 2 integers")
if style[:3] == 'sci':
sb = True
elif style in ['plain', 'comma']:
elif style == 'plain':
sb = False
if style == 'plain':
cb = False
else:
cb = True
raise NotImplementedError("comma style remains to be added")
elif style == 'comma':
raise NotImplementedError("comma style remains to be added")
elif style == '':
sb = None
else:
Expand Down
526 changes: 526 additions & 0 deletions lib/matplotlib/mpl-data/stylelib/_classic_test.mplstyle

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ xtick.major.top : True # draw x axis top major ticks
xtick.major.bottom : True # draw x axis bottom major ticks
xtick.minor.top : True # draw x axis top minor ticks
xtick.minor.bottom : True # draw x axis bottom minor ticks
xtick.alignment : center

ytick.left : True # draw ticks on the left side
ytick.right : True # draw ticks on the right side
Expand All @@ -271,6 +272,7 @@ ytick.major.left : True # draw y axis left major ticks
ytick.major.right : True # draw y axis right major ticks
ytick.minor.left : True # draw y axis left minor ticks
ytick.minor.right : True # draw y axis right minor ticks
ytick.alignment : center
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be xtick.alignment added as well?


### GRIDS
grid.color : k # grid color
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ def validate_font_properties(s):
'verbose',
['silent', 'helpful', 'debug', 'debug-annoying'])

_validate_alignment = ValidateInStrings(
'alignment',
['center', 'top', 'bottom', 'baseline',
'center_baseline'])

def validate_whiskers(s):
if s=='range':
return 'range'
Expand Down Expand Up @@ -1195,6 +1200,7 @@ def validate_animation_writer_path(p):
# fontsize of the xtick labels
'xtick.labelsize': ['medium', validate_fontsize],
'xtick.direction': ['out', six.text_type], # direction of xticks
'xtick.alignment': ["center", _validate_alignment],

'ytick.left': [True, validate_bool], # draw ticks on the left side
'ytick.right': [False, validate_bool], # draw ticks on the right side
Expand All @@ -1214,6 +1220,8 @@ def validate_animation_writer_path(p):
# fontsize of the ytick labels
'ytick.labelsize': ['medium', validate_fontsize],
'ytick.direction': ['out', six.text_type], # direction of yticks
'ytick.alignment': ["center_baseline", _validate_alignment],


'grid.color': ['#b0b0b0', validate_color], # grid color
'grid.linestyle': ['-', six.text_type], # solid
Expand Down
51 changes: 25 additions & 26 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import warnings
import unittest

# Note - don't import nose up here - import it only as needed in functions. This
# allows other functions here to be used by pytest-based testing suites without
# requiring nose to be installed.
# Note - don't import nose up here - import it only as needed in functions.
# This allows other functions here to be used by pytest-based testing suites
# without requiring nose to be installed.

import numpy as np

Expand Down Expand Up @@ -163,7 +163,7 @@ def wrapped_callable(*args, **kwargs):
return make_cleanup
else:
result = make_cleanup(style)
style = 'classic'
style = '_classic_test'
return result


Expand Down Expand Up @@ -268,43 +268,42 @@ def do_test(fignum, actual_fname, expected_fname):

def image_comparison(baseline_images=None, extensions=None, tol=0,
freetype_version=None, remove_text=False,
savefig_kwarg=None, style='classic'):
savefig_kwarg=None, style='_classic_test'):
"""
Compare images generated by the test with those specified in
*baseline_images*, which must correspond else an
ImageComparisonFailure exception will be raised.

Keyword arguments:
Arguments
---------
baseline_images : list
A list of strings specifying the names of the images generated by
calls to :meth:`matplotlib.figure.savefig`.

*baseline_images*: list
A list of strings specifying the names of the images generated
by calls to :meth:`matplotlib.figure.savefig`.

*extensions*: [ None | list ]

If *None*, default to all supported extensions.
extensions : [ None | list ]

If None, defaults to all supported extensions.
Otherwise, a list of extensions to test. For example ['png','pdf'].

*tol*: (default 0)
tol : float, optional, default: 0
The RMS threshold above which the test is considered failed.

*freetype_version*: str or tuple
The expected freetype version or range of versions for this
test to pass.
freetype_version : str or tuple
The expected freetype version or range of versions for this test to
pass.

*remove_text*: bool
Remove the title and tick text from the figure before
comparison. This does not remove other, more deliberate,
text, such as legends and annotations.
remove_text : bool
Remove the title and tick text from the figure before comparison.
This does not remove other, more deliberate, text, such as legends and
annotations.

*savefig_kwarg*: dict
savefig_kwarg : dict
Optional arguments that are passed to the savefig method.

*style*: string
Optional name for the base style to apply to the image
test. The test itself can also apply additional styles
if desired. Defaults to the 'classic' style.
style : string
Optional name for the base style to apply to the image test. The test
itself can also apply additional styles if desired. Defaults to the
'_classic_test' style.

"""
if baseline_images is None:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,15 @@ def test_bar_tick_label_multiple():
ax.bar([1, 2.5], [1, 2], width=[0.2, 0.5], tick_label=['a', 'b'],
align='center')

@image_comparison(baseline_images=['bar_tick_label_multiple_old_label_alignment'],
extensions=['png'])
def test_bar_tick_label_multiple_old_alignment():
# Test that the algnment for class is backward compatible
matplotlib.rcParams["ytick.alignment"] = "center"
ax = plt.gca()
ax.bar([1, 2.5], [1, 2], width=[0.2, 0.5], tick_label=['a', 'b'],
align='center')


@image_comparison(baseline_images=['barh_tick_label'],
extensions=['png'])
Expand Down
6 changes: 0 additions & 6 deletions lib/matplotlib/tests/test_backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def create_figure():


# test compiling a figure to pdf with xelatex
@cleanup(style='classic')
@switch_backend('pgf')
def test_xelatex():
if not check_for('xelatex'):
Expand All @@ -92,7 +91,6 @@ def test_xelatex():


# test compiling a figure to pdf with pdflatex
@cleanup(style='classic')
@switch_backend('pgf')
def test_pdflatex():
if not check_for('pdflatex'):
Expand All @@ -109,7 +107,6 @@ def test_pdflatex():


# test updating the rc parameters for each figure
@cleanup(style='classic')
@switch_backend('pgf')
def test_rcupdate():
if not check_for('xelatex') or not check_for('pdflatex'):
Expand Down Expand Up @@ -142,7 +139,6 @@ def test_rcupdate():


# test backend-side clipping, since large numbers are not supported by TeX
@cleanup(style='classic')
@switch_backend('pgf')
def test_pathclip():
if not check_for('xelatex'):
Expand All @@ -161,7 +157,6 @@ def test_pathclip():


# test mixed mode rendering
@cleanup(style='classic')
@switch_backend('pgf')
def test_mixedmode():
if not check_for('xelatex'):
Expand All @@ -178,7 +173,6 @@ def test_mixedmode():


# test bbox_inches clipping
@cleanup(style='classic')
@switch_backend('pgf')
def test_bbox_inches():
if not check_for('xelatex'):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import warnings


@cleanup(style='classic')
@cleanup(style='_classic_test')
def test_MaxNLocator():
loc = mticker.MaxNLocator(nbins=5)
test_value = np.array([20., 40., 60., 80., 100.])
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_SymmetricalLogLocator_set_params():
nose.tools.assert_equal(sym.numticks, 8)


@cleanup(style='classic')
@cleanup(style='_classic_test')
def test_ScalarFormatter_offset_value():
fig, ax = plt.subplots()
formatter = ax.get_xaxis().get_major_formatter()
Expand Down