Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2addc5b

Browse files
committed
Use batch ax.set() method
1 parent 30cbdf7 commit 2addc5b

29 files changed

+47
-101
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
def init():
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
del xdata[:]
2827
del ydata[:]
2928
line.set_data(xdata, ydata)

examples/axisartist/axis_direction.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
def setup_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
def setup_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
return ax
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
def setup_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
return ax
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
for ax, case in zip(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
for ax, case in zip(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
for ax, case in zip(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/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
if 17 in seg_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
for ax in axs.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
for ax in axs.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
for ax in [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
for ax in axs.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
for ax in axs.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

examples/style_sheets/style_sheets_reference.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def plot_scatter(ax, prng, nb_samples=100):
2121
for mu, sigma, marker in [(-.5, 0.75, 'o'), (0.75, 1., 's')]:
2222
x, y = prng.normal(loc=mu, scale=sigma, size=(2, nb_samples))
2323
ax.plot(x, y, ls='none', marker=marker)
24-
ax.set_xlabel('X-label')
25-
ax.set_title('Axes title')
24+
ax.set(xlabel='X-label', title='Axes title')
2625
return ax
2726

2827

@@ -63,8 +62,7 @@ def plot_colored_circles(ax, prng, nb_samples=15):
6362
radius=1.0, color=sty_dict['color']))
6463
# Force the limits to be the same across the styles (because different
6564
# styles may have different numbers of available colors).
66-
ax.set_xlim([-4, 8])
67-
ax.set_ylim([-5, 6])
65+
ax.set(xlim=[-4, 8], ylim=[-5, 6])
6866
ax.set_aspect('equal', adjustable='box') # to plot circles as circles
6967
return ax
7068

@@ -75,9 +73,7 @@ def plot_image_and_patch(ax, prng, size=(20, 20)):
7573
ax.imshow(values, interpolation='none')
7674
c = plt.Circle((5, 5), radius=5, label='patch')
7775
ax.add_patch(c)
78-
# Remove ticks
79-
ax.set_xticks([])
80-
ax.set_yticks([])
76+
ax.set(xticks=[], yticks=[]) # Remove ticks
8177

8278

8379
def plot_histograms(ax, prng, nb_samples=10000):

examples/subplots_axes_and_figures/align_labels_demo.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727
for i in range(2):
2828
ax = fig.add_subplot(gs[1, i])
2929
ax.plot(np.arange(1., 0., -0.1) * 2000., np.arange(1., 0., -0.1))
30-
ax.set_ylabel('YLabel1 %d' % i)
31-
ax.set_xlabel('XLabel1 %d' % i)
30+
ax.set(xlabel=f'XLabel1 {i}', ylabel=f'YLabel1 {i}')
3231
if i == 0:
33-
for tick in ax.get_xticklabels():
34-
tick.set_rotation(55)
32+
ax.tick_params(rotation=55)
3533
fig.align_labels() # same as fig.align_xlabels(); fig.align_ylabels()
3634

3735
plt.show()

examples/text_labels_and_annotations/text_rotation.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def addtext(ax, props):
2929
ax.text(4.5, 0.5, 'text -45', props, rotation=-45)
3030
for x in range(0, 5):
3131
ax.scatter(x + 0.5, 0.5, color='r', alpha=0.5)
32-
ax.set_yticks([0, .5, 1])
33-
ax.set_xticks(np.arange(0, 5.1, 0.5))
34-
ax.set_xlim(0, 5)
32+
ax.set(yticks=[0, .5, 1], xticks=np.arange(0, 5.1, 0.5), xlim=(0, 5))
3533
ax.grid(True)
3634

3735

0 commit comments

Comments
 (0)