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

Commitabdaba5

Browse files
committed
Change constrained_layout=True to layout='constrained'
as the former is discouraged, seehttps://matplotlib.org/3.5.0/api/figure_api.html#matplotlib.figure.Figure
1 parent2a62854 commitabdaba5

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

‎tutorials/introductory/usage.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
data['b']=data['a']+10*np.random.randn(50)
121121
data['d']=np.abs(data['d'])*100
122122

123-
fig,ax=plt.subplots(figsize=(5,2.7),constrained_layout=True)
123+
fig,ax=plt.subplots(figsize=(5,2.7),layout='constrained')
124124
ax.scatter('a','b',c='c',s='d',data=data)
125125
ax.set_xlabel('entry a')
126126
ax.set_ylabel('entry b');
@@ -147,7 +147,7 @@
147147

148148
# Note that even in the explicit style, we use `.pyplot.figure` to create the
149149
# Figure.
150-
fig,ax=plt.subplots(figsize=(5,2.7),constrained_layout=True)
150+
fig,ax=plt.subplots(figsize=(5,2.7),layout='constrained')
151151
ax.plot(x,x,label='linear')# Plot some data on the axes.
152152
ax.plot(x,x**2,label='quadratic')# Plot more data on the axes...
153153
ax.plot(x,x**3,label='cubic')# ... and some more.
@@ -161,7 +161,7 @@
161161

162162
x=np.linspace(0,2,100)# Sample data.
163163

164-
plt.figure(figsize=(5,2.7),constrained_layout=True)
164+
plt.figure(figsize=(5,2.7),layout='constrained')
165165
plt.plot(x,x,label='linear')# Plot some data on the (implicit) axes.
166166
plt.plot(x,x**2,label='quadratic')# etc.
167167
plt.plot(x,x**3,label='cubic')
@@ -284,7 +284,7 @@ def my_plotter(ax, data1, data2, param_dict):
284284

285285
mu,sigma=115,15
286286
x=mu+sigma*np.random.randn(10000)
287-
fig,ax=plt.subplots(figsize=(5,2.7),constrained_layout=True)
287+
fig,ax=plt.subplots(figsize=(5,2.7),layout='constrained')
288288
# the histogram of the data
289289
n,bins,patches=ax.hist(x,50,density=1,facecolor='C0',alpha=0.75)
290290

@@ -380,7 +380,7 @@ def my_plotter(ax, data1, data2, param_dict):
380380
# :doc:`/gallery/scales/scales` for other examples). Here we set the scale
381381
# manually:
382382

383-
fig,axs=plt.subplots(1,2,figsize=(5,2.7),constrained_layout=True)
383+
fig,axs=plt.subplots(1,2,figsize=(5,2.7),layout='constrained')
384384
xdata=np.arange(len(data1))# make an ordinal for this
385385
data=10**data1
386386
axs[0].plot(xdata,data)
@@ -401,7 +401,7 @@ def my_plotter(ax, data1, data2, param_dict):
401401
# Axis objects to put tick marks. A simple interface to this is
402402
# `~.Axes.set_xticks`:
403403

404-
fig,axs=plt.subplots(2,1,constrained_layout=True)
404+
fig,axs=plt.subplots(2,1,layout='constrained')
405405
axs[0].plot(xdata,data1)
406406
axs[0].set_title('Automatic ticks')
407407

@@ -424,7 +424,7 @@ def my_plotter(ax, data1, data2, param_dict):
424424
# well as floating point numbers. These get special locators and formatters
425425
# as appropriate. For dates:
426426

427-
fig,ax=plt.subplots(figsize=(5,2.7),constrained_layout=True)
427+
fig,ax=plt.subplots(figsize=(5,2.7),layout='constrained')
428428
dates=np.arange(np.datetime64('2021-11-15'),np.datetime64('2021-12-25'),
429429
np.timedelta64(1,'h'))
430430
data=np.cumsum(np.random.randn(len(dates)))
@@ -439,7 +439,7 @@ def my_plotter(ax, data1, data2, param_dict):
439439
# For strings, we get categorical plotting (see:
440440
# :doc:`/gallery/lines_bars_and_markers/categorical_variables`).
441441

442-
fig,ax=plt.subplots(figsize=(5,2.7),constrained_layout=True)
442+
fig,ax=plt.subplots(figsize=(5,2.7),layout='constrained')
443443
categories= ['turnips','rutabaga','cucumber','pumpkins']
444444

445445
ax.bar(categories,np.random.rand(len(categories)));
@@ -464,7 +464,7 @@ def my_plotter(ax, data1, data2, param_dict):
464464
# represent the data in different scales or units.
465465

466466

467-
fig, (ax1,ax3)=plt.subplots(1,2,figsize=(8,2.7),constrained_layout=True)
467+
fig, (ax1,ax3)=plt.subplots(1,2,figsize=(8,2.7),layout='constrained')
468468
l1,=ax1.plot(t,s)
469469
ax2=ax1.twinx()
470470
l2,=ax2.plot(t,range(len(t)),'C1')
@@ -485,7 +485,7 @@ def my_plotter(ax, data1, data2, param_dict):
485485
X,Y=np.meshgrid(np.linspace(-3,3,128),np.linspace(-3,3,128))
486486
Z= (1-X/2+X**5+Y**3)*np.exp(-X**2-Y**2)
487487

488-
fig,axs=plt.subplots(2,2,constrained_layout=True)
488+
fig,axs=plt.subplots(2,2,layout='constrained')
489489
pc=axs[0,0].pcolormesh(X,Y,Z,vmin=-1,vmax=1,cmap='RdBu_r')
490490
fig.colorbar(pc,ax=axs[0,0])
491491
axs[0,0].set_title('pcolormesh()')
@@ -551,7 +551,7 @@ def my_plotter(ax, data1, data2, param_dict):
551551
# with Axes objects spanning columns or rows, using `~.pyplot.subplot_mosaic`.
552552

553553
fig,axd=plt.subplot_mosaic([['upleft','right'],
554-
['lowleft','right']],constrained_layout=True)
554+
['lowleft','right']],layout='constrained')
555555
axd['upleft'].set_title('upleft')
556556
axd['lowleft'].set_title('lowleft')
557557
axd['right'].set_title('right');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp