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

Commitd0584cd

Browse files
committed
Deprecate Axes.apply_aspect()
1 parentecba9d2 commitd0584cd

File tree

10 files changed

+45
-33
lines changed

10 files changed

+45
-33
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``Axes.apply_aspect()``
2+
~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated. Please use `.Figure.draw_without_rendering` if you need to
4+
update the layout of the figure prior to drawing on a canvas.

‎lib/matplotlib/_constrained_layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def compress_fixed_aspect(layoutgrids, fig):
267267
foraxinfig.axes:
268268
ifnothasattr(ax,'get_subplotspec'):
269269
continue
270-
ax.apply_aspect()
270+
ax._apply_aspect()
271271
sub=ax.get_subplotspec()
272272
_gs=sub.get_gridspec()
273273
ifgsisNone:

‎lib/matplotlib/_tight_bbox.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ def adjust_bbox(fig, bbox_inches, fixed_dpi=None):
2929
current_pos=ax.get_position(original=False).frozen()
3030
ax.set_axes_locator(lambdaa,r,_pos=current_pos:_pos)
3131
# override the method that enforces the aspect ratio on the Axes
32-
if'apply_aspect'inax.__dict__:
33-
old_aspect.append(ax.apply_aspect)
32+
if'_apply_aspect'inax.__dict__:
33+
old_aspect.append(ax._apply_aspect)
3434
else:
3535
old_aspect.append(sentinel)
36-
ax.apply_aspect=lambdapos=None:None
36+
ax._apply_aspect=lambdapos=None:None
3737

3838
defrestore_bbox():
3939
forax,loc,aspectinzip(fig.axes,locator_list,old_aspect):
4040
ax.set_axes_locator(loc)
4141
ifaspectissentinel:
4242
# delete our no-op function which un-hides the original method
43-
delax.apply_aspect
43+
delax._apply_aspect
4444
else:
45-
ax.apply_aspect=aspect
45+
ax._apply_aspect=aspect
4646

4747
fig.bbox=origBbox
4848
fig.bbox_inches=origBboxInches

‎lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def inset_axes(self, bounds, *, transform=None, zorder=5, **kwargs):
376376
inset_ax=projection_class(self.figure,bounds,zorder=zorder,**pkw)
377377

378378
# this locator lets the axes move if in data coordinates.
379-
# it gets called in `ax.apply_aspect() (of all places)
379+
# it gets called in `ax._apply_aspect() (of all places)
380380
inset_ax.set_axes_locator(inset_locator)
381381

382382
self.add_child_axes(inset_ax)
@@ -444,7 +444,7 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
444444
"""
445445
# to make the axes connectors work, we need to apply the aspect to
446446
# the parent axes.
447-
self.apply_aspect()
447+
self._apply_aspect()
448448

449449
iftransformisNone:
450450
transform=self.transData

‎lib/matplotlib/axes/_base.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ def get_position(self, original=False):
10411041
else:
10421042
locator=self.get_axes_locator()
10431043
ifnotlocator:
1044-
self.apply_aspect()
1044+
self._apply_aspect()
10451045
returnself._position.frozen()
10461046

10471047
defset_position(self,pos,which='both'):
@@ -1719,7 +1719,7 @@ def set_adjustable(self, adjustable, share=False):
17191719
andany(getattr(ax.get_data_ratio,"__func__",None)
17201720
!=_AxesBase.get_data_ratio
17211721
foraxinaxs)):
1722-
# Limits adjustment byapply_aspect assumes that the axes' aspect
1722+
# Limits adjustment by_apply_aspect assumes that the axes' aspect
17231723
# ratio can be computed from the data limits and scales.
17241724
raiseValueError("Cannot set Axes adjustable to 'datalim' for "
17251725
"Axes which override 'get_data_ratio'")
@@ -1855,7 +1855,11 @@ def get_data_ratio(self):
18551855
ysize=max(abs(tymax-tymin),1e-30)
18561856
returnysize/xsize
18571857

1858+
@_api.deprecated("3.6",alternative="Figure.draw_without_rendering")
18581859
defapply_aspect(self,position=None):
1860+
self._apply_aspect(position)
1861+
1862+
def_apply_aspect(self,position=None):
18591863
"""
18601864
Adjust the Axes for a specified data aspect ratio.
18611865
@@ -2954,7 +2958,7 @@ def _update_title_position(self, renderer):
29542958
axs=self._twinned_axes.get_siblings(self)+self.child_axes
29552959
foraxinself.child_axes:# Child positions must be updated first.
29562960
locator=ax.get_axes_locator()
2957-
ax.apply_aspect(locator(self,renderer)iflocatorelseNone)
2961+
ax._apply_aspect(locator(self,renderer)iflocatorelseNone)
29582962

29592963
fortitleintitles:
29602964
x,_=title.get_position()
@@ -3017,7 +3021,7 @@ def draw(self, renderer):
30173021

30183022
# loop over self and child Axes...
30193023
locator=self.get_axes_locator()
3020-
self.apply_aspect(locator(self,renderer)iflocatorelseNone)
3024+
self._apply_aspect(locator(self,renderer)iflocatorelseNone)
30213025

30223026
artists=self.get_children()
30233027
artists.remove(self.patch)
@@ -4382,7 +4386,7 @@ def get_tightbbox(self, renderer=None, call_axes_locator=True,
43824386
returnNone
43834387

43844388
locator=self.get_axes_locator()
4385-
self.apply_aspect(
4389+
self._apply_aspect(
43864390
locator(self,renderer)iflocatorandcall_axes_locatorelseNone)
43874391

43884392
foraxisinself._axis_map.values():

‎lib/matplotlib/axes/_secondary_axes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ def set_location(self, location):
114114
# this locator lets the axes move in the parent axes coordinates.
115115
# so it never needs to know where the parent is explicitly in
116116
# figure coordinates.
117-
# it gets called in ax.apply_aspect() (of all places)
117+
# it gets called in ax._apply_aspect() (of all places)
118118
self.set_axes_locator(
119119
_TransformedBoundsLocator(bounds,self._parent.transAxes))
120120

121-
defapply_aspect(self,position=None):
121+
def_apply_aspect(self,position=None):
122122
# docstring inherited.
123123
self._set_lims()
124-
super().apply_aspect(position)
124+
super()._apply_aspect(position)
125125

126126
@_docstring.copy(Axis.set_ticks)
127127
defset_ticks(self,ticks,labels=None,*,minor=False,**kwargs):

‎lib/matplotlib/figure.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def __init__(self, **kwargs):
193193
self.set(**kwargs)
194194

195195
def_get_draw_artists(self,renderer):
196-
"""Also runsapply_aspect"""
196+
"""Also runs_apply_aspect"""
197197
artists=self.get_children()
198198
forsfiginself.subfigs:
199199
artists.remove(sfig)
@@ -208,12 +208,12 @@ def _get_draw_artists(self, renderer):
208208
key=lambdaartist:artist.get_zorder())
209209
foraxinself._localaxes:
210210
locator=ax.get_axes_locator()
211-
ax.apply_aspect(locator(ax,renderer)iflocatorelseNone)
211+
ax._apply_aspect(locator(ax,renderer)iflocatorelseNone)
212212

213213
forchildinax.get_children():
214-
ifhasattr(child,'apply_aspect'):
214+
ifhasattr(child,'_apply_aspect'):
215215
locator=child.get_axes_locator()
216-
child.apply_aspect(
216+
child._apply_aspect(
217217
locator(child,renderer)iflocatorelseNone)
218218
returnartists
219219

‎lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,7 +5273,7 @@ def test_shared_with_aspect_2():
52735273
axs[0].set_aspect(2,share=True)
52745274
axs[0].plot([1,2], [3,4])
52755275
axs[1].plot([3,4], [1,2])
5276-
plt.draw()# Triggerapply_aspect().
5276+
plt.draw()# Trigger_apply_aspect().
52775277
assertaxs[0].get_xlim()==axs[1].get_xlim()
52785278
assertaxs[0].get_ylim()==axs[1].get_ylim()
52795279

@@ -5286,7 +5286,7 @@ def test_shared_with_aspect_3():
52865286
axs[1].set_aspect(0.5,adjustable=adjustable)
52875287
axs[0].plot([1,2], [3,4])
52885288
axs[1].plot([3,4], [1,2])
5289-
plt.draw()# Triggerapply_aspect().
5289+
plt.draw()# Trigger_apply_aspect().
52905290
assertaxs[0].get_xlim()!=axs[1].get_xlim()
52915291
assertaxs[0].get_ylim()==axs[1].get_ylim()
52925292
fig_aspect=fig.bbox_inches.height/fig.bbox_inches.width
@@ -6814,8 +6814,8 @@ def test_inset():
68146814
fig,ax=plt.subplots()
68156815
ax.pcolormesh(x,y,z[:-1, :-1])
68166816
ax.set_aspect(1.)
6817-
ax.apply_aspect()
6818-
# we need toapply_aspect to make the drawing below work.
6817+
ax._apply_aspect()
6818+
# we need to_apply_aspect to make the drawing below work.
68196819

68206820
xlim= [1.5,2.15]
68216821
ylim= [2,2.5]
@@ -6840,8 +6840,8 @@ def test_zoom_inset():
68406840
fig,ax=plt.subplots()
68416841
ax.pcolormesh(x,y,z[:-1, :-1])
68426842
ax.set_aspect(1.)
6843-
ax.apply_aspect()
6844-
# we need toapply_aspect to make the drawing below work.
6843+
ax._apply_aspect()
6844+
# we need to_apply_aspect to make the drawing below work.
68456845

68466846
# Make the inset_axes... Position axes coordinates...
68476847
axin1=ax.inset_axes([0.7,0.7,0.35,0.35])
@@ -7376,7 +7376,7 @@ def test_aspect_nonlinear_adjustable_datalim():
73767376
yscale="logit",ylim=(1/101,1/11),
73777377
aspect=1,adjustable="datalim")
73787378
ax.margins(0)
7379-
ax.apply_aspect()
7379+
ax._apply_aspect()
73807380

73817381
assertax.get_xlim()==pytest.approx([1*10**(1/2),100/10**(1/2)])
73827382
assertax.get_ylim()== (1/101,1/11)

‎lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ def _update_viewlim(self): # Inline after deprecation elapses.
8282
else:
8383
_api.check_in_list([None,"equal","transform"],mode=mode)
8484

85+
@_api.deprecated("3.6",alternative="Figure.draw_if_interactive")
8586
defapply_aspect(self,position=None):
87+
self._apply_aspect(position)
88+
89+
def_apply_aspect(self,position=None):
8690
self._update_viewlim()
87-
super().apply_aspect()
91+
super()._apply_aspect()
8892

8993
# end of aux_transform support
9094

@@ -126,13 +130,13 @@ def draw(self, renderer):
126130
iflocator:
127131
pos=locator(self,renderer)
128132
self.set_position(pos,which="active")
129-
self.apply_aspect(pos)
133+
self._apply_aspect(pos)
130134
else:
131-
self.apply_aspect()
135+
self._apply_aspect()
132136

133137
rect=self.get_position()
134138
foraxinself.parasites:
135-
ax.apply_aspect(rect)
139+
ax._apply_aspect(rect)
136140
self._children.extend(ax.get_children())
137141

138142
super().draw(renderer)

‎lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def set_box_aspect(self, aspect, *, zoom=1):
387387
self._box_aspect=aspect
388388
self.stale=True
389389

390-
defapply_aspect(self,position=None):
390+
def_apply_aspect(self,position=None):
391391
ifpositionisNone:
392392
position=self.get_position(original=True)
393393

@@ -420,7 +420,7 @@ def draw(self, renderer):
420420
# it adjusts the view limits and the size of the bounding box
421421
# of the Axes
422422
locator=self.get_axes_locator()
423-
self.apply_aspect(locator(self,renderer)iflocatorelseNone)
423+
self._apply_aspect(locator(self,renderer)iflocatorelseNone)
424424

425425
# add the projection matrix to the renderer
426426
self.M=self.get_proj()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp