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

Commitb677c24

Browse files
committed
Use batch ax.set() method
1 parent30cbdf7 commitb677c24

File tree

35 files changed

+56
-115
lines changed

35 files changed

+56
-115
lines changed

‎examples/animation/animate_decay.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ def data_gen():
2222

2323

2424
definit():
25-
ax.set_ylim(-1.1,1.1)
26-
ax.set_xlim(0,10)
25+
ax.set(xlim=(0,10),ylim=(-1.1,1.1))
2726
delxdata[:]
2827
delydata[:]
2928
line.set_data(xdata,ydata)

‎examples/animation/bayes_update.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ def __init__(self, ax, prob=0.5):
3030
self.ax=ax
3131

3232
# Set up plot parameters
33-
self.ax.set_xlim(0,1)
34-
self.ax.set_ylim(0,10)
33+
self.ax.set(xlim=(0,1),ylim=(0,10))
3534
self.ax.grid(True)
3635

3736
# This vertical line represents the theoretical value, to

‎examples/animation/rain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
# Create new Figure and an Axes which fills it.
2121
fig=plt.figure(figsize=(7,7))
2222
ax=fig.add_axes([0,0,1,1],frameon=False)
23-
ax.set_xlim(0,1),ax.set_xticks([])
24-
ax.set_ylim(0,1),ax.set_yticks([])
23+
ax.set(xticks=[],xlim=(0,1),
24+
yticks=[],ylim=(0,1))
2525

2626
# Create rain data
2727
n_drops=50

‎examples/animation/strip_chart.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def __init__(self, ax, maxt=2, dt=0.02):
2121
self.ydata= [0]
2222
self.line=Line2D(self.tdata,self.ydata)
2323
self.ax.add_line(self.line)
24-
self.ax.set_ylim(-.1,1.1)
25-
self.ax.set_xlim(0,self.maxt)
24+
self.ax.set(xlim=(0,self.maxt),ylim=(-.1,1.1))
2625

2726
defupdate(self,y):
2827
lastt=self.tdata[-1]

‎examples/axisartist/axis_direction.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
defsetup_axes(fig,pos):
1212
ax=fig.add_subplot(pos,axes_class=axisartist.Axes)
1313

14-
ax.set_ylim(-0.1,1.5)
15-
ax.set_yticks([0,1])
14+
ax.set(ylim=(-0.1,1.5),yticks=[0,1])
1615

1716
ax.axis[:].set_visible(False)
1817

‎examples/axisartist/demo_ticklabel_alignment.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,16 @@ def setup_axes(fig, pos):
2323
fig.subplots_adjust(left=0.5,hspace=0.7)
2424

2525
ax=setup_axes(fig,311)
26-
ax.set_ylabel("ha=right")
27-
ax.set_xlabel("va=baseline")
26+
ax.set(xlabel="va=baseline",ylabel="ha=right")
2827

2928
ax=setup_axes(fig,312)
3029
ax.axis["left"].major_ticklabels.set_ha("center")
3130
ax.axis["bottom"].major_ticklabels.set_va("top")
32-
ax.set_ylabel("ha=center")
33-
ax.set_xlabel("va=top")
31+
ax.set(xlabel="va=top",ylabel="ha=center")
3432

3533
ax=setup_axes(fig,313)
3634
ax.axis["left"].major_ticklabels.set_ha("left")
3735
ax.axis["bottom"].major_ticklabels.set_va("bottom")
38-
ax.set_ylabel("ha=left")
39-
ax.set_xlabel("va=bottom")
36+
ax.set(xlabel="va=bottom",ylabel="ha=left")
4037

4138
plt.show()

‎examples/axisartist/demo_ticklabel_direction.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
defsetup_axes(fig,pos):
1313
ax=fig.add_subplot(pos,axes_class=axislines.Axes)
14-
ax.set_yticks([0.2,0.8])
15-
ax.set_xticks([0.2,0.8])
14+
ax.set(xticks=[0.2,0.8],yticks=[0.2,0.8])
1615
returnax
1716

1817

‎examples/axisartist/simple_axis_direction03.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
defsetup_axes(fig,pos):
1313
ax=fig.add_subplot(pos,axes_class=axisartist.Axes)
14-
ax.set_yticks([0.2,0.8])
15-
ax.set_xticks([0.2,0.8])
14+
ax.set(xticks=[0.2,0.8],yticks=[0.2,0.8])
1615
returnax
1716

1817

‎examples/event_handling/poly_editor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def on_mouse_move(self, event):
205205
ax.add_patch(poly)
206206
p=PolygonInteractor(ax,poly)
207207

208-
ax.set_title('Click and drag a point to move it')
209-
ax.set_xlim((-2,2))
210-
ax.set_ylim((-2,2))
208+
ax.set(xlim=(-2,2),ylim=(-2,2),
209+
title='Click and drag a point to move it')
210+
211211
plt.show()

‎examples/images_contours_and_fields/affine_image.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def do_plot(ax, Z, transform):
4040
x1,x2,y1,y2=im.get_extent()
4141
ax.plot([x1,x2,x2,x1,x1], [y1,y1,y2,y2,y1],"y--",
4242
transform=trans_data)
43-
ax.set_xlim(-5,5)
44-
ax.set_ylim(-4,4)
43+
ax.set(xlim=(-5,5),ylim=(-4,4))
4544

4645

4746
# prepare image and figure

‎examples/images_contours_and_fields/pcolormesh_grids.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ def _annotate(ax, x, y, title):
4242
# this all gets repeated below:
4343
X,Y=np.meshgrid(x,y)
4444
ax.plot(X.flat,Y.flat,'o',color='m')
45-
ax.set_xlim(-0.7,5.2)
46-
ax.set_ylim(-0.7,3.2)
47-
ax.set_title(title)
45+
ax.set(xlim=(-0.7,5.2),ylim=(-0.7,3.2),title=title)
4846

4947
_annotate(ax,x,y,"shading='flat'")
5048

‎examples/lines_bars_and_markers/eventcollection_demo.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@
5252
ax.add_collection(yevents2)
5353

5454
# set the limits
55-
ax.set_xlim([0,1])
56-
ax.set_ylim([0,1])
57-
58-
ax.set_title('line plot with data points')
55+
ax.set(xlim=[0,1],ylim=[0,1],title='line plot with data points')
5956

6057
# display the plot
6158
plt.show()

‎examples/lines_bars_and_markers/markevery_demo.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ def trim_axs(axs, N):
6565
axs=plt.figure(figsize=figsize,constrained_layout=True).subplots(rows,cols)
6666
axs=trim_axs(axs,len(cases))
6767
forax,caseinzip(axs,cases):
68-
ax.set_title('markevery=%s'%str(case))
69-
ax.set_xscale('log')
70-
ax.set_yscale('log')
68+
ax.set(xscale='log',yscale='log',title=f'markevery={case!r}')
7169
ax.plot(x,y,'o',ls='-',ms=4,markevery=case)
7270

7371
###############################################################################
@@ -79,10 +77,8 @@ def trim_axs(axs, N):
7977
axs=plt.figure(figsize=figsize,constrained_layout=True).subplots(rows,cols)
8078
axs=trim_axs(axs,len(cases))
8179
forax,caseinzip(axs,cases):
82-
ax.set_title('markevery=%s'%str(case))
8380
ax.plot(x,y,'o',ls='-',ms=4,markevery=case)
84-
ax.set_xlim((6,6.7))
85-
ax.set_ylim((1.1,1.7))
81+
ax.set(xlim=(6,6.7),ylim=(1.1,1.7),title=f'markevery={case!r}')
8682

8783
# define data for polar plots
8884
r=np.linspace(0,3.0,200)
@@ -95,7 +91,7 @@ def trim_axs(axs, N):
9591
rows,cols,subplot_kw={'projection':'polar'})
9692
axs=trim_axs(axs,len(cases))
9793
forax,caseinzip(axs,cases):
98-
ax.set_title('markevery=%s'%str(case))
94+
ax.set_title(f'markevery={case!r}')
9995
ax.plot(theta,r,'o',ls='-',ms=4,markevery=case)
10096

10197
plt.show()

‎examples/misc/demo_agg_filter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ def drop_shadow_line(ax):
224224
shadow.set_agg_filter(gauss)
225225
shadow.set_rasterized(True)# to support mixed-mode renderers
226226

227-
ax.set_xlim(0.,1.)
228-
ax.set_ylim(0.,1.)
227+
ax.set(xlim=(0,1),ylim=(0,1))
229228

230229
ax.xaxis.set_visible(False)
231230
ax.yaxis.set_visible(False)

‎examples/misc/demo_ribbon_box.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def main():
7878
ax.add_artist(RibbonBoxImage(ax,bbox,bc,interpolation="bicubic"))
7979
ax.annotate(str(h), (year,h),va="bottom",ha="center")
8080

81-
ax.set_xlim(years[0]-0.5,years[-1]+0.5)
82-
ax.set_ylim(0,10000)
81+
ax.set(xlim=(years[0]-0.5,years[-1]+0.5),ylim=(0,10000))
8382

8483
background_gradient=np.zeros((2,2,4))
8584
background_gradient[:, :, :3]= [1,1,0]

‎examples/mplot3d/contour3d_3.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@
2626
cset=ax.contour(X,Y,Z,zdir='x',offset=-40,cmap=cm.coolwarm)
2727
cset=ax.contour(X,Y,Z,zdir='y',offset=40,cmap=cm.coolwarm)
2828

29-
ax.set_xlim(-40,40)
30-
ax.set_ylim(-40,40)
31-
ax.set_zlim(-100,100)
32-
33-
ax.set_xlabel('X')
34-
ax.set_ylabel('Y')
35-
ax.set_zlabel('Z')
29+
ax.set(xlabel='X',xlim=(-40,40),
30+
ylabel='Y',ylim=(-40,40),
31+
zlabel='Z',zlim=(-100,100))
3632

3733
plt.show()

‎examples/mplot3d/contourf3d_2.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@
2626
cset=ax.contourf(X,Y,Z,zdir='x',offset=-40,cmap=cm.coolwarm)
2727
cset=ax.contourf(X,Y,Z,zdir='y',offset=40,cmap=cm.coolwarm)
2828

29-
ax.set_xlim(-40,40)
30-
ax.set_ylim(-40,40)
31-
ax.set_zlim(-100,100)
32-
33-
ax.set_xlabel('X')
34-
ax.set_ylabel('Y')
35-
ax.set_zlabel('Z')
29+
ax.set(xlabel='X',xlim=(-40,40),
30+
ylabel='Y',ylim=(-40,40),
31+
zlabel='Z',zlim=(-100,100))
3632

3733
plt.show()

‎examples/pyplots/text_commands.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313

1414
ax=fig.add_subplot()
1515
fig.subplots_adjust(top=0.85)
16-
ax.set_title('axes title')
17-
18-
ax.set_xlabel('xlabel')
19-
ax.set_ylabel('ylabel')
16+
ax.set(xlabel='xlabel',ylabel='ylabel',title='axes title')
2017

2118
ax.text(3,8,'boxed italics text in data coords',style='italic',
2219
bbox={'facecolor':'red','alpha':0.5,'pad':10})

‎examples/scales/log_bar.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
ax.set_xticklabels(map(str,x))
2525
ax.set_yscale('log')
2626

27-
ax.set_xlabel('x')
28-
ax.set_ylabel('y')
27+
ax.set(xlabel='x',ylabel='y')
2928

3029
plt.show()

‎examples/shapes_and_collections/line_collection.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232

3333
# We need to set the plot limits.
3434
fig,ax=plt.subplots()
35-
ax.set_xlim(x.min(),x.max())
36-
ax.set_ylim(ys.min(),ys.max())
35+
ax.set(xlim=(x.min(),x.max()),ylim=(ys.min(),ys.max()))
3736

3837
# *colors* is sequence of rgba tuples.
3938
# *linestyle* is a string or dash tuple. Legal string values are
@@ -62,8 +61,7 @@
6261

6362
# We need to set the plot limits, they will not autoscale
6463
fig,ax=plt.subplots()
65-
ax.set_xlim(np.min(x),np.max(x))
66-
ax.set_ylim(np.min(ys),np.max(ys))
64+
ax.set(xlim=(np.min(x),np.max(x)),ylim=(np.min(ys),np.max(ys)))
6765

6866
# colors is sequence of rgba tuples
6967
# linestyle is a string or dash tuple. Legal string values are

‎examples/showcase/mandelbrot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ def mandelbrot_set(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon=2.0):
6060
M=light.shade(M,cmap=plt.cm.hot,vert_exag=1.5,
6161
norm=colors.PowerNorm(0.3),blend_mode='hsv')
6262
ax.imshow(M,extent=[xmin,xmax,ymin,ymax],interpolation="bicubic")
63-
ax.set_xticks([])
64-
ax.set_yticks([])
63+
ax.set(xticks=[],yticks=[])
6564

6665
# Some advertisement for matplotlib
6766
year=time.strftime("%Y")

‎examples/showcase/xkcd.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
ax=fig.add_axes((0.1,0.2,0.8,0.7))
1919
ax.spines.right.set_color('none')
2020
ax.spines.top.set_color('none')
21-
ax.set_xticks([])
22-
ax.set_yticks([])
23-
ax.set_ylim([-30,10])
21+
ax.set(xticks=[],yticks=[],ylim=[-30,10])
2422

2523
data=np.ones(100)
2624
data[70:]-=np.arange(30)
@@ -31,8 +29,7 @@
3129

3230
ax.plot(data)
3331

34-
ax.set_xlabel('time')
35-
ax.set_ylabel('my overall health')
32+
ax.set(xlabel='time',ylabel='my overall health')
3633
fig.text(
3734
0.5,0.05,
3835
'"Stove Ownership" from xkcd by Randall Munroe',
@@ -50,8 +47,8 @@
5047
ax.spines.right.set_color('none')
5148
ax.spines.top.set_color('none')
5249
ax.xaxis.set_ticks_position('bottom')
53-
ax.set_xticks([0,1])
54-
ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT','REFUTED BY\nEXPERIMENT'])
50+
ax.set_xticks([0,1],
51+
['CONFIRMED BY\nEXPERIMENT','REFUTED BY\nEXPERIMENT'])
5552
ax.set_xlim([-0.5,1.5])
5653
ax.set_yticks([])
5754
ax.set_ylim([0,110])

‎examples/specialty_plots/leftventricle_bulleye.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
122122
if17inseg_bold:
123123
ax.plot(theta0,r0,'-k',lw=linewidth+2)
124124

125-
ax.set_ylim([0,1])
126-
ax.set_yticklabels([])
127-
ax.set_xticklabels([])
125+
ax.set(ylim=[0,1],xticklabels=[],yticklabels=[])
128126

129127

130128
# Create the fake data

‎examples/specialty_plots/skewt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ def upper_xlim(self):
250250
# Disables the log-formatting that comes with semilogy
251251
ax.yaxis.set_major_formatter(ScalarFormatter())
252252
ax.yaxis.set_minor_formatter(NullFormatter())
253-
ax.set_yticks(np.linspace(100,1000,10))
254-
ax.set_ylim(1050,100)
253+
ax.set(yticks=np.linspace(100,1000,10),ylim=(1050,100))
255254

256255
ax.xaxis.set_major_locator(MultipleLocator(10))
257256
ax.set_xlim(-50,50)

‎examples/statistics/boxplot.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848
axs[1,2].set_title('showfliers=False',fontsize=fs)
4949

5050
foraxinaxs.flat:
51-
ax.set_yscale('log')
52-
ax.set_yticklabels([])
51+
ax.set(yscale='log',yticklabels=[])
5352

5453
fig.subplots_adjust(hspace=0.4)
5554
plt.show()
@@ -88,8 +87,7 @@
8887
axs[1,2].set_title('whis=[15, 85]\n#percentiles',fontsize=fs)
8988

9089
foraxinaxs.flat:
91-
ax.set_yscale('log')
92-
ax.set_yticklabels([])
90+
ax.set(yscale='log',yticklabels=[])
9391

9492
fig.suptitle("I never said they'd be pretty")
9593
fig.subplots_adjust(hspace=0.4)

‎examples/statistics/boxplot_color.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
# adding horizontal grid lines
4848
foraxin [ax1,ax2]:
4949
ax.yaxis.grid(True)
50-
ax.set_xlabel('Three separate samples')
51-
ax.set_ylabel('Observed values')
50+
ax.set(xlabel='Three separate samples',ylabel='Observed values')
5251

5352
plt.show()
5453

‎examples/statistics/bxp.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@
6363
axs[1,2].set_title('showfliers=False',fontsize=fs)
6464

6565
foraxinaxs.flat:
66-
ax.set_yscale('log')
67-
ax.set_yticklabels([])
66+
ax.set(yscale='log',yticklabels=[])
6867

6968
fig.subplots_adjust(hspace=0.4)
7069
plt.show()
@@ -96,8 +95,7 @@
9695
axs[1,1].set_title('Custom mean\nas line',fontsize=fs)
9796

9897
foraxinaxs.flat:
99-
ax.set_yscale('log')
100-
ax.set_yticklabels([])
98+
ax.set(yscale='log',yticklabels=[])
10199

102100
fig.suptitle("I never said they'd be pretty")
103101
fig.subplots_adjust(hspace=0.4)

‎examples/statistics/multiple_histograms_side_by_side.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
ax.set_xticks(x_locations)
5858
ax.set_xticklabels(labels)
5959

60-
ax.set_ylabel("Data values")
61-
ax.set_xlabel("Data sets")
60+
ax.set(xlabel="Data sets",ylabel="Data values")
6261

6362
plt.show()
6463

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp