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

Commit2053e8c

Browse files
committed
TST: Use text placeholders for empty legends
These tests use `remove_text=True` and set legend labels to emptystrings. However, they are still affected by font metrics because eventhe empty string is as tall as the line height (which is calculated fromthe height of the "lp" string.)
1 parentf101e49 commit2053e8c

File tree

12 files changed

+533
-389
lines changed

12 files changed

+533
-389
lines changed
Loading
Binary file not shown.
Binary file not shown.

‎lib/matplotlib/tests/baseline_images/test_bbox_tight/bbox_inches_tight.svg

Lines changed: 513 additions & 366 deletions
Loading

‎lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4593,14 +4593,12 @@ def test_hist_stacked_weighted():
45934593

45944594

45954595
@image_comparison(['stem.png'],style='mpl20',remove_text=True)
4596-
deftest_stem():
4596+
deftest_stem(text_placeholders):
45974597
x=np.linspace(0.1,2*np.pi,100)
45984598

45994599
fig,ax=plt.subplots()
4600-
# Label is a single space to force a legend to be drawn, but to avoid any
4601-
# text being drawn
46024600
ax.stem(x,np.cos(x),
4603-
linefmt='C2-.',markerfmt='k+',basefmt='C1-.',label='')
4601+
linefmt='C2-.',markerfmt='k+',basefmt='C1-.',label='stem')
46044602
ax.legend()
46054603

46064604

‎lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,15 @@ def test_pdfpages_fspath():
296296
pdf.savefig(plt.figure())
297297

298298

299-
@image_comparison(['hatching_legend.pdf'])
300-
deftest_hatching_legend():
299+
@image_comparison(['hatching_legend.pdf'],style='mpl20')
300+
deftest_hatching_legend(text_placeholders):
301301
"""Test for correct hatching on patches in legend"""
302-
fig=plt.figure(figsize=(1,2))
302+
fig=plt.figure(figsize=(1.5,1))
303303

304304
a=Rectangle([0,0],0,0,facecolor="green",hatch="XXXX")
305305
b=Rectangle([0,0],0,0,facecolor="blue",hatch="XXXX")
306306

307-
fig.legend([a,b,a,b], ["","","",""])
307+
fig.legend([a,b,a,b], ["green","blue","green","blue"])
308308

309309

310310
@image_comparison(['grayscale_alpha.pdf'])

‎lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
frommpl_toolkits.axes_grid1.inset_locatorimportinset_axes
1212

1313

14-
@image_comparison(['bbox_inches_tight'],remove_text=True,
14+
@image_comparison(['bbox_inches_tight'],remove_text=True,style='mpl20',
1515
savefig_kwarg={'bbox_inches':'tight'})
16-
deftest_bbox_inches_tight():
16+
deftest_bbox_inches_tight(text_placeholders):
1717
#: Test that a figure saved using bbox_inches='tight' is clipped correctly
1818
data= [[66386,174296,75131,577908,32015],
1919
[58230,381139,78045,99308,160454],
2020
[89135,80552,152558,497981,603535],
2121
[78415,81858,150656,193263,69638],
2222
[139361,331509,343164,781380,52269]]
2323

24-
col_labels=row_labels= ['']*5
24+
col_labels=row_labels= ['a','b','c','d','e']
2525

2626
rows=len(data)
2727
ind=np.arange(len(col_labels))+0.3# the x locations for the groups
@@ -31,13 +31,13 @@ def test_bbox_inches_tight():
3131
# the bottom values for stacked bar chart
3232
fig,ax=plt.subplots(1,1)
3333
forrowinrange(rows):
34-
ax.bar(ind,data[row],width,bottom=yoff,align='edge',color='b')
34+
ax.bar(ind,data[row],width,bottom=yoff,align='edge')
3535
yoff=yoff+data[row]
36-
cell_text.append([''])
36+
cell_text.append(['x'])
3737
plt.xticks([])
3838
plt.xlim(0,5)
39-
plt.legend(['']*5,loc=(1.2,0.2))
40-
fig.legend(['']*5,bbox_to_anchor=(0,0.2),loc='lower left')
39+
plt.legend(['a','b','c','d','e'],loc=(1.2,0.2))
40+
fig.legend(['a','b','c','d','e'],bbox_to_anchor=(0,0.2),loc='lower left')
4141
# Add a table at the bottom of the axes
4242
cell_text.reverse()
4343
plt.table(cellText=cell_text,rowLabels=row_labels,colLabels=col_labels,

‎lib/matplotlib/tests/test_lines.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ def test_marker_as_markerstyle():
332332

333333

334334
@image_comparison(['striped_line.png'],remove_text=True,style='mpl20')
335-
deftest_striped_lines():
335+
deftest_striped_lines(text_placeholders):
336336
rng=np.random.default_rng(19680801)
337337
_,ax=plt.subplots()
338338
ax.plot(rng.uniform(size=12),color='orange',gapcolor='blue',
339-
linestyle='--',lw=5,label='')
339+
linestyle='--',lw=5,label='blue in orange')
340340
ax.plot(rng.uniform(size=12),color='red',gapcolor='black',
341-
linestyle=(0, (2,5,4,2)),lw=5,label='',alpha=0.5)
341+
linestyle=(0, (2,5,4,2)),lw=5,label='black in red',alpha=0.5)
342342
ax.legend(handlelength=5)
343343

344344

‎lib/matplotlib/tests/test_patheffects.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,8 @@ def test_collection():
135135
'edgecolor':'blue'})
136136

137137

138-
@image_comparison(['tickedstroke'],remove_text=True,extensions=['png'],
139-
tol=0.22)# Increased tolerance due to fixed clipping.
140-
deftest_tickedstroke():
138+
@image_comparison(['tickedstroke.png'],remove_text=True,style='mpl20')
139+
deftest_tickedstroke(text_placeholders):
141140
fig, (ax1,ax2,ax3)=plt.subplots(1,3,figsize=(12,4))
142141
path=Path.unit_circle()
143142
patch=patches.PathPatch(path,facecolor='none',lw=2,path_effects=[
@@ -149,13 +148,13 @@ def test_tickedstroke():
149148
ax1.set_xlim(-2,2)
150149
ax1.set_ylim(-2,2)
151150

152-
ax2.plot([0,1], [0,1],label='',
151+
ax2.plot([0,1], [0,1],label='C0',
153152
path_effects=[path_effects.withTickedStroke(spacing=7,
154153
angle=135)])
155154
nx=101
156155
x=np.linspace(0.0,1.0,nx)
157156
y=0.3*np.sin(x*8)+0.4
158-
ax2.plot(x,y,label='',path_effects=[path_effects.withTickedStroke()])
157+
ax2.plot(x,y,label='C1',path_effects=[path_effects.withTickedStroke()])
159158

160159
ax2.legend()
161160

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp