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

Commit89bfa2e

Browse files
tacaswellQuLogic
authored andcommitted
Backport PR#29908: TST: Use text placeholders for empty legends
1 parent0ef15b6 commit89bfa2e

File tree

12 files changed

+921
-390
lines changed

12 files changed

+921
-390
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: 900 additions & 369 deletions
Loading

‎lib/matplotlib/tests/test_axes.py

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

45074507

45084508
@image_comparison(['stem.png'],style='mpl20',remove_text=True)
4509-
deftest_stem():
4509+
deftest_stem(text_placeholders):
45104510
x=np.linspace(0.1,2*np.pi,100)
45114511

45124512
fig,ax=plt.subplots()
4513-
# Label is a single space to force a legend to be drawn, but to avoid any
4514-
# text being drawn
45154513
ax.stem(x,np.cos(x),
4516-
linefmt='C2-.',markerfmt='k+',basefmt='C1-.',label='')
4514+
linefmt='C2-.',markerfmt='k+',basefmt='C1-.',label='stem')
45174515
ax.legend()
45184516

45194517

‎lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,16 @@ def test_pdfpages_fspath():
312312
pdf.savefig(plt.figure())
313313

314314

315-
@image_comparison(['hatching_legend.pdf'])
316-
deftest_hatching_legend():
315+
@image_comparison(['hatching_legend.pdf'],style='mpl20')
316+
deftest_hatching_legend(text_placeholders):
317317
"""Test for correct hatching on patches in legend"""
318318
fig=plt.figure(figsize=(1,2))
319319

320320
a=Rectangle([0,0],0,0,facecolor="green",hatch="XXXX")
321321
b=Rectangle([0,0],0,0,facecolor="blue",hatch="XXXX")
322322

323+
# Verify that hatches in PDFs work after empty labels. See
324+
# https://github.com/matplotlib/matplotlib/issues/4469
323325
fig.legend([a,b,a,b], ["","","",""])
324326

325327

‎lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
frommatplotlib.tickerimportFuncFormatter
1111

1212

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

23-
col_labels=row_labels= ['']*5
23+
col_labels= ('Freeze','Wind','Flood','Quake','Hail')
24+
row_labels= [f'{x} year'forxin (100,50,20,10,5)]
2425

2526
rows=len(data)
2627
ind=np.arange(len(col_labels))+0.3# the x locations for the groups
@@ -30,13 +31,13 @@ def test_bbox_inches_tight():
3031
# the bottom values for stacked bar chart
3132
fig,ax=plt.subplots(1,1)
3233
forrowinrange(rows):
33-
ax.bar(ind,data[row],width,bottom=yoff,align='edge',color='b')
34+
ax.bar(ind,data[row],width,bottom=yoff,align='edge')
3435
yoff=yoff+data[row]
35-
cell_text.append([''])
36+
cell_text.append([f'{x/1000:1.1f}'forxinyoff])
3637
plt.xticks([])
3738
plt.xlim(0,5)
38-
plt.legend(['']*5,loc=(1.2,0.2))
39-
fig.legend(['']*5,bbox_to_anchor=(0,0.2),loc='lower left')
39+
plt.legend(['1','2','3','4','5'],loc=(1.2,0.2))
40+
fig.legend(['a','b','c','d','e'],bbox_to_anchor=(0,0.2),loc='lower left')
4041
# Add a table at the bottom of the axes
4142
cell_text.reverse()
4243
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