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

Commitb6dff32

Browse files
committed
TST: Remove image from offsetbox tight layout test
1 parent3b29800 commitb6dff32

File tree

1 file changed

+53
-23
lines changed

1 file changed

+53
-23
lines changed

‎lib/matplotlib/tests/test_tightlayout.py

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ def add_offsetboxes(ax, size=10, margin=.1, color='black'):
194194
"""
195195
m,mp=margin,1+margin
196196
anchor_points= [(-m,-m), (-m,.5), (-m,mp),
197-
(mp,.5), (.5,mp), (mp,mp),
198-
(.5,-m), (mp,-m), (.5,-m)]
197+
(.5,mp), (mp,mp), (mp,.5),
198+
(mp,-m), (.5,-m)]
199199
forpointinanchor_points:
200200
da=DrawingArea(size,size)
201201
background=Rectangle((0,0),width=size,
@@ -215,48 +215,78 @@ def add_offsetboxes(ax, size=10, margin=.1, color='black'):
215215
bbox_transform=ax.transAxes,
216216
borderpad=0.)
217217
ax.add_artist(anchored_box)
218-
returnanchored_box
219218

220219

221-
@image_comparison(['tight_layout_offsetboxes1','tight_layout_offsetboxes2'],
222-
style='mpl20')
223220
deftest_tight_layout_offsetboxes():
224-
#1.
221+
#0.
225222
# - Create 4 subplots
226223
# - Plot a diagonal line on them
224+
# - Use tight_layout
225+
#
226+
# 1.
227+
# - Same 4 subplots
227228
# - Surround each plot with 7 boxes
228229
# - Use tight_layout
229-
# - See that the squares are included in the tight_layout
230-
#and that the squares in the middle donot overlap
230+
# - See that the squares are included in the tight_layout and that the squares do
231+
# not overlap
231232
#
232233
# 2.
233-
# - Make the squares around the right side axes invisible
234-
# - See that the invisible squares do not affect the
235-
# tight_layout
234+
# - Make the squares around the Axes invisible
235+
# - See that the invisible squares do not affect the tight_layout
236236
rows=cols=2
237237
colors= ['red','blue','green','yellow']
238238
x=y= [0,1]
239239

240-
def_subplots():
241-
_,axs=plt.subplots(rows,cols)
242-
axs=axs.flat
243-
forax,colorinzip(axs,colors):
240+
def_subplots(with_boxes):
241+
fig,axs=plt.subplots(rows,cols)
242+
forax,colorinzip(axs.flat,colors):
244243
ax.plot(x,y,color=color)
245-
add_offsetboxes(ax,20,color=color)
246-
returnaxs
244+
ifwith_boxes:
245+
add_offsetboxes(ax,20,color=color)
246+
returnfig,axs
247+
248+
# 0.
249+
fig0,axs0=_subplots(False)
250+
fig0.tight_layout()
247251

248252
# 1.
249-
axs=_subplots()
250-
plt.tight_layout()
253+
fig1,axs1=_subplots(True)
254+
fig1.tight_layout()
255+
256+
# The AnchoredOffsetbox should be added to the bounding of the Axes, causing them to
257+
# be smaller than the plain figure.
258+
forax0,ax1inzip(axs0.flat,axs1.flat):
259+
bbox0=ax0.get_position()
260+
bbox1=ax1.get_position()
261+
assertbbox1.x0>bbox0.x0
262+
assertbbox1.x1<bbox0.x1
263+
assertbbox1.y0>bbox0.y0
264+
assertbbox1.y1<bbox0.y1
265+
266+
# No AnchoredOffsetbox should overlap with another.
267+
bboxes= []
268+
forax1inaxs1.flat:
269+
forchildinax1.get_children():
270+
ifnotisinstance(child,AnchoredOffsetbox):
271+
continue
272+
bbox=child.get_window_extent()
273+
forother_bboxinbboxes:
274+
assertnotbbox.overlaps(other_bbox)
275+
bboxes.append(bbox)
251276

252277
# 2.
253-
axs=_subplots()
254-
foraxin(axs[cols-1::rows]):
278+
fig2,axs2=_subplots(True)
279+
foraxinaxs2.flat:
255280
forchildinax.get_children():
256281
ifisinstance(child,AnchoredOffsetbox):
257282
child.set_visible(False)
258-
259-
plt.tight_layout()
283+
fig2.tight_layout()
284+
# The invisible AnchoredOffsetbox should not count for tight layout, so it should
285+
# look the same as when they were never added.
286+
forax0,ax2inzip(axs0.flat,axs2.flat):
287+
bbox0=ax0.get_position()
288+
bbox2=ax2.get_position()
289+
assert_array_equal(bbox2.get_points(),bbox0.get_points())
260290

261291

262292
deftest_empty_layout():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp