Skip to content

Commit 14ca211

Browse files
committed
Loosen tolerance for text-only differences
1 parent 5d14187 commit 14ca211

File tree

9 files changed

+60
-30
lines changed

9 files changed

+60
-30
lines changed

lib/matplotlib/tests/test_axes.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,9 @@ def test_matshow(fig_test, fig_ref):
238238
ax_ref.xaxis.set_ticks_position('both')
239239

240240

241+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
241242
@image_comparison([f'formatter_ticker_{i:03d}.png' for i in range(1, 6)],
242-
tol=0 if platform.machine() == 'x86_64' else 0.031)
243+
tol=0.02 if platform.machine() == 'x86_64' else 0.031)
243244
def test_formatter_ticker():
244245
import matplotlib.testing.jpl_units as units
245246
units.register()
@@ -808,7 +809,8 @@ def test_annotate_signature():
808809
assert p1 == p2
809810

810811

811-
@image_comparison(['fill_units.png'], savefig_kwarg={'dpi': 60})
812+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
813+
@image_comparison(['fill_units.png'], savefig_kwarg={'dpi': 60}, tol=0.2)
812814
def test_fill_units():
813815
import matplotlib.testing.jpl_units as units
814816
units.register()
@@ -1514,7 +1516,8 @@ def test_pcolormesh_log_scale(fig_test, fig_ref):
15141516
ax.set_xscale('log')
15151517

15161518

1517-
@image_comparison(['pcolormesh_datetime_axis.png'], style='mpl20')
1519+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
1520+
@image_comparison(['pcolormesh_datetime_axis.png'], style='mpl20', tol=0.3)
15181521
def test_pcolormesh_datetime_axis():
15191522
# Remove this line when this test image is regenerated.
15201523
plt.rcParams['pcolormesh.snap'] = False
@@ -1542,7 +1545,8 @@ def test_pcolormesh_datetime_axis():
15421545
label.set_rotation(30)
15431546

15441547

1545-
@image_comparison(['pcolor_datetime_axis.png'], style='mpl20')
1548+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
1549+
@image_comparison(['pcolor_datetime_axis.png'], style='mpl20', tol=0.3)
15461550
def test_pcolor_datetime_axis():
15471551
fig = plt.figure()
15481552
fig.subplots_adjust(hspace=0.4, top=0.98, bottom=.15)
@@ -2737,7 +2741,8 @@ def test_stairs_options():
27372741
ax.legend(loc=0)
27382742

27392743

2740-
@image_comparison(['test_stairs_datetime.png'])
2744+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
2745+
@image_comparison(['test_stairs_datetime.png'], tol=0.2)
27412746
def test_stairs_datetime():
27422747
f, ax = plt.subplots(constrained_layout=True)
27432748
ax.stairs(np.arange(36),
@@ -6438,7 +6443,8 @@ def test_pie_frame_grid():
64386443
plt.axis('equal')
64396444

64406445

6441-
@image_comparison(['pie_rotatelabels_true.png'], style='mpl20', tol=0.009)
6446+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
6447+
@image_comparison(['pie_rotatelabels_true.png'], style='mpl20', tol=0.1)
64426448
def test_pie_rotatelabels_true():
64436449
# The slices will be ordered and plotted counter-clockwise.
64446450
labels = 'Hogwarts', 'Frogs', 'Dogs', 'Logs'

lib/matplotlib/tests/test_colorbar.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,15 @@ def test_colorbar_extension_inverted_axis(orientation, extend, expected):
152152
assert len(cbar._extend_patches) == 1
153153

154154

155+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
155156
@pytest.mark.parametrize('use_gridspec', [True, False])
156157
@image_comparison(['cbar_with_orientation',
157158
'cbar_locationing',
158159
'double_cbar',
159160
'cbar_sharing',
160161
],
161162
extensions=['png'], remove_text=True,
162-
savefig_kwarg={'dpi': 40})
163+
savefig_kwarg={'dpi': 40}, tol=0.05)
163164
def test_colorbar_positioning(use_gridspec):
164165
# Remove this line when this test image is regenerated.
165166
plt.rcParams['pcolormesh.snap'] = False
@@ -731,7 +732,8 @@ def test_colorbar_label():
731732
assert cbar3.ax.get_xlabel() == 'horizontal cbar'
732733

733734

734-
@image_comparison(['colorbar_keeping_xlabel.png'], style='mpl20')
735+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
736+
@image_comparison(['colorbar_keeping_xlabel.png'], style='mpl20', tol=0.03)
735737
def test_keeping_xlabel():
736738
# github issue #23398 - xlabels being ignored in colorbar axis
737739
arr = np.arange(25).reshape((5, 5))

lib/matplotlib/tests/test_contour.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ def test_contour_manual_moveto():
127127
assert clabels[0].get_text() == "0"
128128

129129

130+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
130131
@image_comparison(['contour_disconnected_segments'],
131-
remove_text=True, style='mpl20', extensions=['png'])
132+
remove_text=True, style='mpl20', extensions=['png'], tol=0.01)
132133
def test_contour_label_with_disconnected_segments():
133134
x, y = np.mgrid[-1:1:21j, -1:1:21j]
134135
z = 1 / np.sqrt(0.01 + (x + 0.3) ** 2 + y ** 2)
@@ -229,7 +230,8 @@ def test_lognorm_levels(n_levels):
229230
assert len(visible_levels) <= n_levels + 1
230231

231232

232-
@image_comparison(['contour_datetime_axis.png'], style='mpl20')
233+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
234+
@image_comparison(['contour_datetime_axis.png'], style='mpl20', tol=0.3)
233235
def test_contour_datetime_axis():
234236
fig = plt.figure()
235237
fig.subplots_adjust(hspace=0.4, top=0.98, bottom=.15)

lib/matplotlib/tests/test_dates.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def test_date_axhspan():
152152
fig.subplots_adjust(left=0.25)
153153

154154

155-
@image_comparison(['date_axvspan.png'])
155+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
156+
@image_comparison(['date_axvspan.png'], tol=0.06)
156157
def test_date_axvspan():
157158
# test axvspan with date inputs
158159
t0 = datetime.datetime(2000, 1, 20)
@@ -176,7 +177,8 @@ def test_date_axhline():
176177
fig.subplots_adjust(left=0.25)
177178

178179

179-
@image_comparison(['date_axvline.png'])
180+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
181+
@image_comparison(['date_axvline.png'], tol=0.08)
180182
def test_date_axvline():
181183
# test axvline with date inputs
182184
t0 = datetime.datetime(2000, 1, 20)
@@ -226,7 +228,8 @@ def wrapper():
226228
return wrapper
227229

228230

229-
@image_comparison(['RRuleLocator_bounds.png'])
231+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
232+
@image_comparison(['RRuleLocator_bounds.png'], tol=0.07)
230233
def test_RRuleLocator():
231234
import matplotlib.testing.jpl_units as units
232235
units.register()
@@ -270,7 +273,8 @@ def test_RRuleLocator_close_minmax():
270273
assert list(map(str, mdates.num2date(loc.tick_values(d1, d2)))) == expected
271274

272275

273-
@image_comparison(['DateFormatter_fractionalSeconds.png'])
276+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
277+
@image_comparison(['DateFormatter_fractionalSeconds.png'], tol=0.1)
274278
def test_DateFormatter():
275279
import matplotlib.testing.jpl_units as units
276280
units.register()

lib/matplotlib/tests/test_figure.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
import matplotlib.dates as mdates
2626

2727

28+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
2829
@image_comparison(['figure_align_labels'], extensions=['png', 'svg'],
29-
tol=0 if platform.machine() == 'x86_64' else 0.01)
30+
tol=0.1 if platform.machine() == 'x86_64' else 0.01)
3031
def test_align_labels():
3132
fig = plt.figure(layout='tight')
3233
gs = gridspec.GridSpec(3, 3)
@@ -66,9 +67,10 @@ def test_align_labels():
6667
fig.align_labels()
6768

6869

70+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
6971
@image_comparison(['figure_align_titles_tight.png',
7072
'figure_align_titles_constrained.png'],
71-
tol=0 if platform.machine() == 'x86_64' else 0.022,
73+
tol=0.3 if platform.machine() == 'x86_64' else 0.022,
7274
style='mpl20')
7375
def test_align_titles():
7476
for layout in ['tight', 'constrained']:
@@ -322,7 +324,8 @@ def test_add_subplot_invalid():
322324
fig.add_subplot(ax)
323325

324326

325-
@image_comparison(['figure_suptitle.png'])
327+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
328+
@image_comparison(['figure_suptitle.png'], tol=0.02)
326329
def test_suptitle():
327330
fig, _ = plt.subplots()
328331
fig.suptitle('hello', color='r')
@@ -1398,8 +1401,9 @@ def test_subfigure_ss():
13981401
fig.suptitle('Figure suptitle', fontsize='xx-large')
13991402

14001403

1404+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
14011405
@image_comparison(['test_subfigure_double.png'], style='mpl20',
1402-
savefig_kwarg={'facecolor': 'teal'})
1406+
savefig_kwarg={'facecolor': 'teal'}, tol=0.02)
14031407
def test_subfigure_double():
14041408
# test assigning the subfigure via subplotspec
14051409
np.random.seed(19680801)

lib/matplotlib/tests/test_polar.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ def test_polar_theta_position():
212212
ax.set_theta_direction('clockwise')
213213

214214

215-
@image_comparison(['polar_rlabel_position.png'], style='default')
215+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
216+
@image_comparison(['polar_rlabel_position.png'], style='default', tol=0.07)
216217
def test_polar_rlabel_position():
217218
fig = plt.figure()
218219
ax = fig.add_subplot(projection='polar')
@@ -227,7 +228,8 @@ def test_polar_title_position():
227228
ax.set_title('foo')
228229

229230

230-
@image_comparison(['polar_theta_wedge.png'], style='default')
231+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
232+
@image_comparison(['polar_theta_wedge.png'], style='default', tol=0.2)
231233
def test_polar_theta_limits():
232234
r = np.arange(0, 3.0, 0.01)
233235
theta = 2*np.pi*r

lib/matplotlib/tests/test_text.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def test_multiline():
137137
ax.set_yticks([])
138138

139139

140-
@image_comparison(['multiline2'], style='mpl20')
140+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
141+
@image_comparison(['multiline2'], style='mpl20', tol=0.05)
141142
def test_multiline2():
142143
# Remove this line when this test image is regenerated.
143144
plt.rcParams['text.kerning_factor'] = 6
@@ -208,7 +209,8 @@ def test_antialiasing():
208209
mpl.rcParams['text.antialiased'] = False # Should not affect existing text.
209210

210211

211-
@image_comparison(['text_contains.png'])
212+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
213+
@image_comparison(['text_contains.png'], tol=0.04)
212214
def test_contains():
213215
fig = plt.figure()
214216
ax = plt.axes()
@@ -277,7 +279,8 @@ def test_titles():
277279
ax.set_yticks([])
278280

279281

280-
@image_comparison(['text_alignment'], style='mpl20')
282+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
283+
@image_comparison(['text_alignment'], style='mpl20', tol=0.08)
281284
def test_alignment():
282285
plt.figure()
283286
ax = plt.subplot(1, 1, 1)
@@ -1096,8 +1099,9 @@ def test_empty_annotation_get_window_extent():
10961099
assert points[0, 1] == 50.0
10971100

10981101

1102+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
10991103
@image_comparison(baseline_images=['basictext_wrap'],
1100-
extensions=['png'])
1104+
extensions=['png'], tol=0.3)
11011105
def test_basic_wrap():
11021106
fig = plt.figure()
11031107
plt.axis([0, 10, 0, 10])
@@ -1113,8 +1117,9 @@ def test_basic_wrap():
11131117
plt.text(-1, 0, t, ha='left', rotation=-15, wrap=True)
11141118

11151119

1120+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
11161121
@image_comparison(baseline_images=['fonttext_wrap'],
1117-
extensions=['png'])
1122+
extensions=['png'], tol=0.3)
11181123
def test_font_wrap():
11191124
fig = plt.figure()
11201125
plt.axis([0, 10, 0, 10])
@@ -1146,8 +1151,9 @@ def test_va_for_angle():
11461151
assert alignment in ['center', 'top', 'baseline']
11471152

11481153

1154+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
11491155
@image_comparison(baseline_images=['xtick_rotation_mode'],
1150-
remove_text=False, extensions=['png'], style='mpl20')
1156+
remove_text=False, extensions=['png'], style='mpl20', tol=0.3)
11511157
def test_xtick_rotation_mode():
11521158
fig, ax = plt.subplots(figsize=(12, 1))
11531159
ax.set_yticks([])
@@ -1166,8 +1172,9 @@ def test_xtick_rotation_mode():
11661172
plt.subplots_adjust(left=0.01, right=0.99, top=.6, bottom=.4)
11671173

11681174

1175+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
11691176
@image_comparison(baseline_images=['ytick_rotation_mode'],
1170-
remove_text=False, extensions=['png'], style='mpl20')
1177+
remove_text=False, extensions=['png'], style='mpl20', tol=0.3)
11711178
def test_ytick_rotation_mode():
11721179
fig, ax = plt.subplots(figsize=(1, 12))
11731180
ax.set_xticks([])

lib/matplotlib/tests/test_units.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ def default_units(value, axis):
8080

8181
# Tests that the conversion machinery works properly for classes that
8282
# work as a facade over numpy arrays (like pint)
83+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
8384
@image_comparison(['plot_pint.png'], style='mpl20',
84-
tol=0 if platform.machine() == 'x86_64' else 0.03)
85+
tol=0.03 if platform.machine() == 'x86_64' else 0.03)
8586
def test_numpy_facade(quantity_converter):
8687
# use former defaults to match existing baseline image
8788
plt.rcParams['axes.formatter.limits'] = -7, 7
@@ -142,8 +143,9 @@ def test_jpl_bar_units():
142143
ax.set_ylim([b - 1 * day, b + w[-1] + (1.001) * day])
143144

144145

146+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
145147
@image_comparison(['jpl_barh_units.png'],
146-
savefig_kwarg={'dpi': 120}, style='mpl20')
148+
savefig_kwarg={'dpi': 120}, style='mpl20', tol=0.02)
147149
def test_jpl_barh_units():
148150
import matplotlib.testing.jpl_units as units
149151
units.register()

lib/matplotlib/tests/test_usetex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,9 @@ def test_pdf_type1_font_subsetting():
226226
_old_gs_version = True
227227

228228

229+
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
229230
@image_comparison(baseline_images=['rotation'], extensions=['eps', 'pdf', 'png', 'svg'],
230-
style='mpl20', tol=3.91 if _old_gs_version else 0)
231+
style='mpl20', tol=3.91 if _old_gs_version else 0.2)
231232
def test_rotation():
232233
mpl.rcParams['text.usetex'] = True
233234

0 commit comments

Comments
 (0)