Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit03e540f

Browse files
authored
Merge pull request#8081 from NelleV/fix_7906_2.0
FIX label vertical alignment can now be specified
2 parents752d6c6 +40d5e41 commit03e540f

File tree

10 files changed

+586
-44
lines changed

10 files changed

+586
-44
lines changed

‎doc/users/dflt_style_changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ values is a single line of python
1818
See:ref:`customizing-with-matplotlibrc-files` for details about how to
1919
persistently and selectively revert many of these changes.
2020

21+
2122
..contents::Table of Contents
2223
:depth: 2
2324
:local:

‎lib/matplotlib/axes/_base.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,12 @@ def get_xaxis_text1_transform(self, pad_points):
731731
place axis elements in different locations.
732732
733733
"""
734+
labels_align=matplotlib.rcParams["xtick.alignment"]
735+
734736
return (self.get_xaxis_transform(which='tick1')+
735737
mtransforms.ScaledTranslation(0,-1*pad_points/72.0,
736738
self.figure.dpi_scale_trans),
737-
"top","center")
739+
"top",labels_align)
738740

739741
defget_xaxis_text2_transform(self,pad_points):
740742
"""
@@ -757,10 +759,11 @@ def get_xaxis_text2_transform(self, pad_points):
757759
place axis elements in different locations.
758760
759761
"""
762+
labels_align=matplotlib.rcParams["xtick.alignment"]
760763
return (self.get_xaxis_transform(which='tick2')+
761764
mtransforms.ScaledTranslation(0,pad_points/72.0,
762765
self.figure.dpi_scale_trans),
763-
"bottom","center")
766+
"bottom",labels_align)
764767

765768
defget_yaxis_transform(self,which='grid'):
766769
"""
@@ -808,10 +811,11 @@ def get_yaxis_text1_transform(self, pad_points):
808811
place axis elements in different locations.
809812
810813
"""
814+
labels_align=matplotlib.rcParams["ytick.alignment"]
811815
return (self.get_yaxis_transform(which='tick1')+
812816
mtransforms.ScaledTranslation(-1*pad_points/72.0,0,
813817
self.figure.dpi_scale_trans),
814-
"center_baseline","right")
818+
labels_align,"right")
815819

816820
defget_yaxis_text2_transform(self,pad_points):
817821
"""
@@ -834,10 +838,12 @@ def get_yaxis_text2_transform(self, pad_points):
834838
place axis elements in different locations.
835839
836840
"""
841+
labels_align=matplotlib.rcParams["ytick.alignment"]
842+
837843
return (self.get_yaxis_transform(which='tick2')+
838844
mtransforms.ScaledTranslation(pad_points/72.0,0,
839845
self.figure.dpi_scale_trans),
840-
"center_baseline","left")
846+
labels_align,"left")
841847

842848
def_update_transScale(self):
843849
self.transScale.set(
@@ -2560,13 +2566,10 @@ def ticklabel_format(self, **kwargs):
25602566
raiseValueError("scilimits must be a sequence of 2 integers")
25612567
ifstyle[:3]=='sci':
25622568
sb=True
2563-
elifstylein ['plain','comma']:
2569+
elifstyle=='plain':
25642570
sb=False
2565-
ifstyle=='plain':
2566-
cb=False
2567-
else:
2568-
cb=True
2569-
raiseNotImplementedError("comma style remains to be added")
2571+
elifstyle=='comma':
2572+
raiseNotImplementedError("comma style remains to be added")
25702573
elifstyle=='':
25712574
sb=None
25722575
else:

‎lib/matplotlib/mpl-data/stylelib/_classic_test.mplstyle

Lines changed: 526 additions & 0 deletions
Large diffs are not rendered by default.

‎lib/matplotlib/mpl-data/stylelib/classic.mplstyle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ xtick.major.top : True # draw x axis top major ticks
254254
xtick.major.bottom : True # draw x axis bottom major ticks
255255
xtick.minor.top : True # draw x axis top minor ticks
256256
xtick.minor.bottom : True # draw x axis bottom minor ticks
257+
xtick.alignment : center
257258

258259
ytick.left : True # draw ticks on the left side
259260
ytick.right : True # draw ticks on the right side
@@ -271,6 +272,7 @@ ytick.major.left : True # draw y axis left major ticks
271272
ytick.major.right : True # draw y axis right major ticks
272273
ytick.minor.left : True # draw y axis left minor ticks
273274
ytick.minor.right : True # draw y axis right minor ticks
275+
ytick.alignment : center
274276

275277
### GRIDS
276278
grid.color : k # grid color

‎lib/matplotlib/rcsetup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,11 @@ def validate_font_properties(s):
465465
'verbose',
466466
['silent','helpful','debug','debug-annoying'])
467467

468+
_validate_alignment=ValidateInStrings(
469+
'alignment',
470+
['center','top','bottom','baseline',
471+
'center_baseline'])
472+
468473
defvalidate_whiskers(s):
469474
ifs=='range':
470475
return'range'
@@ -1195,6 +1200,7 @@ def validate_animation_writer_path(p):
11951200
# fontsize of the xtick labels
11961201
'xtick.labelsize': ['medium',validate_fontsize],
11971202
'xtick.direction': ['out',six.text_type],# direction of xticks
1203+
'xtick.alignment': ["center",_validate_alignment],
11981204

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

12181226
'grid.color': ['#b0b0b0',validate_color],# grid color
12191227
'grid.linestyle': ['-',six.text_type],# solid

‎lib/matplotlib/testing/decorators.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
importwarnings
1313
importunittest
1414

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

1919
importnumpyasnp
2020

@@ -163,7 +163,7 @@ def wrapped_callable(*args, **kwargs):
163163
returnmake_cleanup
164164
else:
165165
result=make_cleanup(style)
166-
style='classic'
166+
style='_classic_test'
167167
returnresult
168168

169169

@@ -268,43 +268,42 @@ def do_test(fignum, actual_fname, expected_fname):
268268

269269
defimage_comparison(baseline_images=None,extensions=None,tol=0,
270270
freetype_version=None,remove_text=False,
271-
savefig_kwarg=None,style='classic'):
271+
savefig_kwarg=None,style='_classic_test'):
272272
"""
273273
Compare images generated by the test with those specified in
274274
*baseline_images*, which must correspond else an
275275
ImageComparisonFailure exception will be raised.
276276
277-
Keyword arguments:
277+
Arguments
278+
---------
279+
baseline_images : list
280+
A list of strings specifying the names of the images generated by
281+
calls to :meth:`matplotlib.figure.savefig`.
278282
279-
*baseline_images*: list
280-
A list of strings specifying the names of the images generated
281-
by calls to :meth:`matplotlib.figure.savefig`.
282-
283-
*extensions*: [ None | list ]
284-
285-
If *None*, default to all supported extensions.
283+
extensions : [ None | list ]
286284
285+
If None, defaults to all supported extensions.
287286
Otherwise, a list of extensions to test. For example ['png','pdf'].
288287
289-
*tol*: (default 0)
288+
tol : float, optional,default: 0
290289
The RMS threshold above which the test is considered failed.
291290
292-
*freetype_version*: str or tuple
293-
The expected freetype version or range of versions for this
294-
test topass.
291+
freetype_version: str or tuple
292+
The expected freetype version or range of versions for this test to
293+
pass.
295294
296-
*remove_text*: bool
297-
Remove the title and tick text from the figure before
298-
comparison.This does not remove other, more deliberate,
299-
text, such as legends andannotations.
295+
remove_text: bool
296+
Remove the title and tick text from the figure before comparison.
297+
This does not remove other, more deliberate, text, such as legends and
298+
annotations.
300299
301-
*savefig_kwarg*: dict
300+
savefig_kwarg: dict
302301
Optional arguments that are passed to the savefig method.
303302
304-
*style*: string
305-
Optional name for the base style to apply to the image
306-
test. The testitself can also apply additional styles
307-
if desired. Defaults to the 'classic' style.
303+
style: string
304+
Optional name for the base style to apply to the image test. The test
305+
itself can also apply additional styles if desired. Defaults to the
306+
'_classic_test' style.
308307
309308
"""
310309
ifbaseline_imagesisNone:

‎lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,15 @@ def test_bar_tick_label_multiple():
11431143
ax.bar([1,2.5], [1,2],width=[0.2,0.5],tick_label=['a','b'],
11441144
align='center')
11451145

1146+
@image_comparison(baseline_images=['bar_tick_label_multiple_old_label_alignment'],
1147+
extensions=['png'])
1148+
deftest_bar_tick_label_multiple_old_alignment():
1149+
# Test that the algnment for class is backward compatible
1150+
matplotlib.rcParams["ytick.alignment"]="center"
1151+
ax=plt.gca()
1152+
ax.bar([1,2.5], [1,2],width=[0.2,0.5],tick_label=['a','b'],
1153+
align='center')
1154+
11461155

11471156
@image_comparison(baseline_images=['barh_tick_label'],
11481157
extensions=['png'])

‎lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def create_figure():
7878

7979

8080
# test compiling a figure to pdf with xelatex
81-
@cleanup(style='classic')
8281
@switch_backend('pgf')
8382
deftest_xelatex():
8483
ifnotcheck_for('xelatex'):
@@ -92,7 +91,6 @@ def test_xelatex():
9291

9392

9493
# test compiling a figure to pdf with pdflatex
95-
@cleanup(style='classic')
9694
@switch_backend('pgf')
9795
deftest_pdflatex():
9896
ifnotcheck_for('pdflatex'):
@@ -109,7 +107,6 @@ def test_pdflatex():
109107

110108

111109
# test updating the rc parameters for each figure
112-
@cleanup(style='classic')
113110
@switch_backend('pgf')
114111
deftest_rcupdate():
115112
ifnotcheck_for('xelatex')ornotcheck_for('pdflatex'):
@@ -142,7 +139,6 @@ def test_rcupdate():
142139

143140

144141
# test backend-side clipping, since large numbers are not supported by TeX
145-
@cleanup(style='classic')
146142
@switch_backend('pgf')
147143
deftest_pathclip():
148144
ifnotcheck_for('xelatex'):
@@ -161,7 +157,6 @@ def test_pathclip():
161157

162158

163159
# test mixed mode rendering
164-
@cleanup(style='classic')
165160
@switch_backend('pgf')
166161
deftest_mixedmode():
167162
ifnotcheck_for('xelatex'):
@@ -178,7 +173,6 @@ def test_mixedmode():
178173

179174

180175
# test bbox_inches clipping
181-
@cleanup(style='classic')
182176
@switch_backend('pgf')
183177
deftest_bbox_inches():
184178
ifnotcheck_for('xelatex'):

‎lib/matplotlib/tests/test_ticker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
importwarnings
1414

1515

16-
@cleanup(style='classic')
16+
@cleanup(style='_classic_test')
1717
deftest_MaxNLocator():
1818
loc=mticker.MaxNLocator(nbins=5)
1919
test_value=np.array([20.,40.,60.,80.,100.])
@@ -172,7 +172,7 @@ def test_SymmetricalLogLocator_set_params():
172172
nose.tools.assert_equal(sym.numticks,8)
173173

174174

175-
@cleanup(style='classic')
175+
@cleanup(style='_classic_test')
176176
deftest_ScalarFormatter_offset_value():
177177
fig,ax=plt.subplots()
178178
formatter=ax.get_xaxis().get_major_formatter()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp