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

Skip to content

Commit bf0c02b

Browse files
committed
TST: Tweak some tests to work better in mpl20 style
1 parent 67a716d commit bf0c02b

11 files changed

Lines changed: 40 additions & 32 deletions

File tree

lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ def test_twin_axis_locators_formatters():
342342

343343
fig = plt.figure()
344344
ax1 = fig.add_subplot(1, 1, 1)
345+
ax1.margins(0)
345346
ax1.plot([0.1, 100], [0, 1])
346347
ax1.yaxis.set_major_locator(majl)
347348
ax1.yaxis.set_minor_locator(minl)
@@ -1845,9 +1846,9 @@ def test_markevery():
18451846
# check marker only plot
18461847
fig, ax = plt.subplots()
18471848
ax.plot(x, y, 'o', label='default')
1848-
ax.plot(x, y, 'd', markevery=None, label='mark all')
1849-
ax.plot(x, y, 's', markevery=10, label='mark every 10')
1850-
ax.plot(x, y, '+', markevery=(5, 20), label='mark every 5 starting at 10')
1849+
ax.plot(x, y+1, 'd', markevery=None, label='mark all')
1850+
ax.plot(x, y+2, 's', markevery=10, label='mark every 10')
1851+
ax.plot(x, y+3, '+', markevery=(5, 20), label='mark every 20 starting at 5')
18511852
ax.legend()
18521853

18531854

@@ -1863,9 +1864,9 @@ def test_markevery_line():
18631864
# check line/marker combos
18641865
fig, ax = plt.subplots()
18651866
ax.plot(x, y, '-o', label='default')
1866-
ax.plot(x, y, '-d', markevery=None, label='mark all')
1867-
ax.plot(x, y, '-s', markevery=10, label='mark every 10')
1868-
ax.plot(x, y, '-+', markevery=(5, 20), label='mark every 5 starting at 10')
1867+
ax.plot(x, y+1, '-d', markevery=None, label='mark all')
1868+
ax.plot(x, y+2, '-s', markevery=10, label='mark every 10')
1869+
ax.plot(x, y+3, '-+', markevery=(5, 20), label='mark every 20 starting at 5')
18691870
ax.legend()
18701871

18711872

@@ -4630,7 +4631,7 @@ def test_errorbar_limits():
46304631
color='red')
46314632

46324633
# including upper and lower limits
4633-
ax.errorbar(x, y+1.5, marker='o', ms=8, xerr=xerr, yerr=yerr,
4634+
ax.errorbar(x, y+1.5, marker='o', ms=6, xerr=xerr, yerr=yerr,
46344635
lolims=lolims, uplims=uplims, ls=ls, color='magenta')
46354636

46364637
# including xlower and xupper limits
@@ -4643,7 +4644,7 @@ def test_errorbar_limits():
46434644
uplims = np.zeros_like(x)
46444645
lolims[[6]] = True
46454646
uplims[[3]] = True
4646-
ax.errorbar(x, y+2.1, marker='o', ms=8, xerr=xerr, yerr=yerr,
4647+
ax.errorbar(x, y+2.1, marker='o', ms=6, xerr=xerr, yerr=yerr,
46474648
xlolims=xlolims, xuplims=xuplims, uplims=uplims,
46484649
lolims=lolims, ls='none', mec='blue', capsize=0,
46494650
color='cyan')

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def test_multi_font_type3():
386386
plt.rc('font', family=fonts, size=16)
387387
plt.rc('pdf', fonttype=3)
388388

389-
fig = plt.figure()
389+
fig = plt.figure(figsize=(8, 6))
390390
fig.text(0.5, 0.5, test_str,
391391
horizontalalignment='center', verticalalignment='center')
392392

@@ -397,7 +397,7 @@ def test_multi_font_type42():
397397
plt.rc('font', family=fonts, size=16)
398398
plt.rc('pdf', fonttype=42)
399399

400-
fig = plt.figure()
400+
fig = plt.figure(figsize=(8, 6))
401401
fig.text(0.5, 0.5, test_str,
402402
horizontalalignment='center', verticalalignment='center')
403403

@@ -457,7 +457,7 @@ def test_truetype_conversion(recwarn):
457457
mpl.rcParams['pdf.fonttype'] = 3
458458
fig, ax = plt.subplots()
459459
ax.text(0, 0, "ABCDE",
460-
font=Path(__file__).parent / "data/mpltest.ttf", fontsize=80)
460+
font=Path(__file__).parent / "data/mpltest.ttf", fontsize=72)
461461
ax.set_xticks([])
462462
ax.set_yticks([])
463463

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def test_multi_font_type3():
321321
plt.rc('font', family=fonts, size=16)
322322
plt.rc('ps', fonttype=3)
323323

324-
fig = plt.figure()
324+
fig = plt.figure(figsize=(8, 6))
325325
fig.text(0.5, 0.5, test_str,
326326
horizontalalignment='center', verticalalignment='center')
327327

@@ -332,7 +332,7 @@ def test_multi_font_type42():
332332
plt.rc('font', family=fonts, size=16)
333333
plt.rc('ps', fonttype=42)
334334

335-
fig = plt.figure()
335+
fig = plt.figure(figsize=(8, 6))
336336
fig.text(0.5, 0.5, test_str,
337337
horizontalalignment='center', verticalalignment='center')
338338

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def test_multi_font_aspath():
533533
plt.rc('font', family=fonts, size=16)
534534
plt.rc('svg', fonttype='path')
535535

536-
fig = plt.figure()
536+
fig = plt.figure(figsize=(8, 6))
537537
fig.text(0.5, 0.5, test_str,
538538
horizontalalignment='center', verticalalignment='center')
539539

@@ -544,7 +544,7 @@ def test_multi_font_astext():
544544
plt.rc('font', family=fonts, size=16)
545545
plt.rc('svg', fonttype='none')
546546

547-
fig = plt.figure()
547+
fig = plt.figure(figsize=(8, 6))
548548
fig.text(0.5, 0.5, test_str,
549549
horizontalalignment='center', verticalalignment='center')
550550

lib/matplotlib/tests/test_legend.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ def test_multiple_keys():
179179
@image_comparison(['rgba_alpha.png'], remove_text=True, style='mpl20',
180180
tol=0 if platform.machine() == 'x86_64' else 0.03)
181181
def test_alpha_rgba():
182+
# This rcParam would override the explicit setting below, so disable it.
183+
plt.rcParams['legend.framealpha'] = None
182184
fig, ax = plt.subplots()
183185
ax.plot(range(10), lw=5)
184186
leg = plt.legend(['Longlabel that will go away'], loc='center')
@@ -219,13 +221,14 @@ def test_framealpha():
219221
x = np.linspace(1, 100, 100)
220222
y = x
221223
plt.plot(x, y, label='mylabel', lw=10)
222-
plt.legend(framealpha=0.5)
224+
plt.legend(framealpha=0.5, loc='upper right')
223225

224226

225227
@image_comparison(['scatter_rc3.png', 'scatter_rc1.png'], remove_text=True,
226228
style='mpl20')
227229
def test_rc():
228230
# using subplot triggers some offsetbox functionality untested elsewhere
231+
mpl.rcParams['legend.scatterpoints'] = 3
229232
plt.figure()
230233
ax = plt.subplot(121)
231234
ax.scatter(np.arange(10), np.arange(10, 0, -1), label='three')

lib/matplotlib/tests/test_patheffects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_patheffect2():
4848
@image_comparison(['patheffect3'], style='mpl20',
4949
tol=0 if platform.machine() == 'x86_64' else 0.019)
5050
def test_patheffect3():
51+
plt.figure(figsize=(8, 6))
5152
p1, = plt.plot([1, 3, 5, 4, 3], 'o-b', lw=4)
5253
p1.set_path_effects([path_effects.SimpleLineShadow(),
5354
path_effects.Normal()])
@@ -87,7 +88,7 @@ def test_patheffects_stroked_text():
8788
]
8889
font_size = 50
8990

90-
ax = plt.axes((0, 0, 1, 1))
91+
ax = plt.figure(figsize=(8, 6)).add_axes((0, 0, 1, 1))
9192
for i, chunk in enumerate(text_chunks):
9293
text = ax.text(x=0.01, y=(0.9 - i * 0.13), s=chunk,
9394
fontdict={'ha': 'left', 'va': 'center',

lib/matplotlib/tests/test_quiver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_quiver_animate():
106106
# Tests fix for #2616
107107
fig, ax = plt.subplots()
108108
Q = draw_quiver(ax, animated=True)
109-
ax.quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$',
109+
ax.quiverkey(Q, 0.5, 0.88, 2, r'$2 \frac{m}{s}$',
110110
labelpos='W', fontproperties={'weight': 'bold'})
111111

112112

lib/matplotlib/tests/test_spines.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def test_spines_data_positions():
8181
ax.spines.bottom.set_position('zero')
8282
ax.set_xlim([-2, 2])
8383
ax.set_ylim([-2, 2])
84+
ax.xaxis.set_ticks_position('both')
85+
ax.yaxis.set_ticks_position('both')
8486

8587

8688
@check_figures_equal()

lib/matplotlib/tests/test_subplots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_exceptions():
184184
tol=0 if platform.machine() == 'x86_64' else 0.028)
185185
def test_subplots_offsettext():
186186
x = np.arange(0, 1e10, 1e9)
187-
y = np.arange(0, 100, 10)+1e4
187+
y = np.arange(0, 100, 10)+1e5
188188
fig, axs = plt.subplots(2, 2, sharex='col', sharey='all')
189189
axs[0, 0].plot(x, x)
190190
axs[1, 0].plot(x, x)

lib/matplotlib/tests/test_text.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def test_antialiasing():
231231
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
232232
@image_comparison(['text_contains.png'], style='mpl20', tol=0.05)
233233
def test_contains():
234-
fig = plt.figure()
234+
fig = plt.figure(figsize=(8, 6))
235235
ax = plt.axes()
236236

237237
mevent = MouseEvent('button_press_event', fig.canvas, 0.5, 0.5, 1, None)
@@ -505,26 +505,26 @@ def test_annotation_negative_fig_coords():
505505
fig, ax = plt.subplots()
506506

507507
ax.annotate('+ pts',
508-
xytext=[10, 120], textcoords='figure points',
509-
xy=[10, 120], xycoords='figure points', fontsize=32)
508+
xytext=[10, 250], textcoords='figure points',
509+
xy=[10, 250], xycoords='figure points', fontsize=32)
510510
ax.annotate('- pts',
511-
xytext=[-10, 180], textcoords='figure points',
512-
xy=[-10, 180], xycoords='figure points', fontsize=32,
511+
xytext=[-10, 310], textcoords='figure points',
512+
xy=[-10, 310], xycoords='figure points', fontsize=32,
513513
va='top')
514514
ax.annotate('+ frac',
515-
xytext=[0.05, 0.55], textcoords='figure fraction',
516-
xy=[0.05, 0.55], xycoords='figure fraction', fontsize=32)
515+
xytext=[0.05, 0.5], textcoords='figure fraction',
516+
xy=[0.05, 0.5], xycoords='figure fraction', fontsize=32)
517517
ax.annotate('- frac',
518-
xytext=[-0.05, 0.5], textcoords='figure fraction',
519-
xy=[-0.05, 0.5], xycoords='figure fraction', fontsize=32,
518+
xytext=[-0.05, 0.45], textcoords='figure fraction',
519+
xy=[-0.05, 0.45], xycoords='figure fraction', fontsize=32,
520520
va='top')
521521

522522
ax.annotate('+ pixels',
523523
xytext=[50, 50], textcoords='figure pixels',
524524
xy=[50, 50], xycoords='figure pixels', fontsize=32)
525525
ax.annotate('- pixels',
526-
xytext=[-50, 100], textcoords='figure pixels',
527-
xy=[-50, 100], xycoords='figure pixels', fontsize=32,
526+
xytext=[-50, 150], textcoords='figure pixels',
527+
xy=[-50, 150], xycoords='figure pixels', fontsize=32,
528528
va='top')
529529

530530

@@ -1144,7 +1144,7 @@ def test_empty_annotation_get_window_extent():
11441144
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
11451145
@image_comparison(['basictext_wrap.png'], style='mpl20', tol=0.3)
11461146
def test_basic_wrap():
1147-
fig = plt.figure()
1147+
fig = plt.figure(figsize=(8, 6))
11481148
plt.axis([0, 10, 0, 10])
11491149
t = "This is a really long string that I'd rather have wrapped so that" \
11501150
" it doesn't go outside of the figure, but if it's long enough it" \
@@ -1161,7 +1161,7 @@ def test_basic_wrap():
11611161
# TODO: tighten tolerance after baseline image is regenerated for text overhaul
11621162
@image_comparison(['fonttext_wrap.png'], style='mpl20', tol=0.3)
11631163
def test_font_wrap():
1164-
fig = plt.figure()
1164+
fig = plt.figure(figsize=(8, 6))
11651165
plt.axis([0, 10, 0, 10])
11661166
t = "This is a really long string that I'd rather have wrapped so that" \
11671167
" it doesn't go outside of the figure, but if it's long enough it" \

0 commit comments

Comments
 (0)