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

Skip to content

Commit 3258404

Browse files
committed
Use (set_)tick_params more in examples.
1 parent 68b9cdd commit 3258404

16 files changed

+25
-65
lines changed

examples/api/logos2.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,10 @@ def add_polar_bar():
7171
bar.set_facecolor(cm.jet(r/10.))
7272
bar.set_alpha(0.6)
7373

74-
for label in ax.get_xticklabels() + ax.get_yticklabels():
75-
label.set_visible(False)
76-
77-
for line in ax.get_ygridlines() + ax.get_xgridlines():
78-
line.set_lw(0.8)
79-
line.set_alpha(0.9)
80-
line.set_ls('-')
81-
line.set_color('0.5')
74+
ax.tick_params(labelbottom=False, labeltop=False,
75+
labelleft=False, labelright=False)
76+
77+
ax.grid(lw=0.8, alpha=0.9, ls='-', color='0.5')
8278

8379
ax.set_yticks(np.arange(1, 9, 2))
8480
ax.set_rmax(9)

examples/axes_grid1/demo_axes_divider.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ def demo_locatable_axes_easy(ax):
7777

7878
plt.colorbar(im, cax=ax_cb)
7979
ax_cb.yaxis.tick_right()
80-
for tl in ax_cb.get_yticklabels():
81-
tl.set_visible(False)
82-
ax_cb.yaxis.tick_right()
80+
ax_cb.yaxis.set_tick_params(labelright=False)
8381

8482

8583
def demo_images_side_by_side(ax):
@@ -94,8 +92,7 @@ def demo_images_side_by_side(ax):
9492

9593
ax.imshow(Z, extent=extent, interpolation="nearest")
9694
ax2.imshow(Z, extent=extent, interpolation="nearest")
97-
for tl in ax2.get_yticklabels():
98-
tl.set_visible(False)
95+
ax2.yaxis.set_tick_params(labelleft=False)
9996

10097

10198
def demo():

examples/axes_grid1/scatter_hist.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)
3232

3333
# make some labels invisible
34-
plt.setp(axHistx.get_xticklabels() + axHisty.get_yticklabels(),
35-
visible=False)
34+
axHistx.xaxis.set_tick_params(labelbottom=False)
35+
axHisty.yaxis.set_tick_params(labelleft=False)
3636

3737
# now determine nice limits by hand:
3838
binwidth = 0.25
@@ -47,14 +47,8 @@
4747
# thus there is no need to manually adjust the xlim and ylim of these
4848
# axis.
4949

50-
#axHistx.axis["bottom"].major_ticklabels.set_visible(False)
51-
for tl in axHistx.get_xticklabels():
52-
tl.set_visible(False)
5350
axHistx.set_yticks([0, 50, 100])
5451

55-
#axHisty.axis["left"].major_ticklabels.set_visible(False)
56-
for tl in axHisty.get_yticklabels():
57-
tl.set_visible(False)
5852
axHisty.set_xticks([0, 50, 100])
5953

6054
plt.draw()

examples/axes_grid1/simple_axes_divider2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
ax[3].set_axes_locator(divider.new_locator(nx=2, nx1=4, ny=0))
2929

3030
for ax1 in ax:
31-
plt.setp(ax1.get_xticklabels()+ax1.get_yticklabels(),
32-
visible=False)
31+
ax1.tick_params(labelbottom=False, labelleft=False)
3332

3433
plt.show()

examples/axes_grid1/simple_axes_divider3.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
divider.set_aspect(1.)
3838

3939
for ax1 in ax:
40-
plt.setp(ax1.get_xticklabels()+ax1.get_yticklabels(),
41-
visible=False)
40+
ax1.tick_params(labelbottom=False, labelleft=False)
4241

4342
plt.show()

examples/pylab_examples/axes_props.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,11 @@
1111

1212
t = np.arange(0.0, 2.0, 0.01)
1313
s = np.sin(2 * np.pi * t)
14+
1415
fig, ax = plt.subplots()
1516
ax.plot(t, s)
16-
ax.grid(True)
17-
18-
ticklines = ax.get_xticklines() + ax.get_yticklines()
19-
gridlines = ax.get_xgridlines() + ax.get_ygridlines()
20-
ticklabels = ax.get_xticklabels() + ax.get_yticklabels()
21-
22-
for line in ticklines:
23-
line.set_linewidth(3)
24-
25-
for line in gridlines:
26-
line.set_linestyle('-.')
2717

28-
for label in ticklabels:
29-
label.set_color('r')
30-
label.set_fontsize('medium')
18+
ax.grid(True, linestyle='-.')
19+
ax.tick_params(labelcolor='r', labelsize='medium', width=3)
3120

3221
plt.show()

examples/pylab_examples/centered_ticklabels.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
associates a label with a tick, and the label can be aligned
88
'center', 'left', or 'right' using the horizontal alignment property::
99
10-
11-
for label in ax.xaxis.get_xticklabels():
12-
label.set_horizontalalignment('right')
10+
ax.xaxis.set_tick_params(horizontalalignment='right')
1311
1412
but this doesn't help center the label between ticks. One solution
1513
is to "fake it". Use the minor ticks to place a tick centered

examples/pylab_examples/date_demo_rrule.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
plt.plot_date(dates, s)
3434
ax.xaxis.set_major_locator(loc)
3535
ax.xaxis.set_major_formatter(formatter)
36-
labels = ax.get_xticklabels()
37-
plt.setp(labels, rotation=30, fontsize=10)
36+
ax.xaxis.set_tick_params(rotation=30, labelsize=10)
3837

3938
plt.show()

examples/pylab_examples/patheffect_demo.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
PathEffects.Stroke(linewidth=5, foreground="w"),
2222
PathEffects.Normal()])
2323

24-
ax1.grid(True, linestyle="-")
25-
2624
pe = [PathEffects.withStroke(linewidth=3,
2725
foreground="w")]
28-
for l in ax1.get_xgridlines() + ax1.get_ygridlines():
29-
l.set_path_effects(pe)
26+
ax1.grid(True, linestyle="-", path_effects=pe)
3027

3128
ax2 = plt.subplot(132)
3229
arr = np.arange(25).reshape((5, 5))

examples/pylab_examples/pythonic_matplotlib.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@
7070
ax1.set_ylabel('1 Hz')
7171
ax1.set_title('A sine wave or two')
7272

73-
for label in ax1.get_xticklabels():
74-
label.set_color('r')
73+
ax1.xaxis.set_tick_params(labelcolor='r')
7574

7675

7776
ax2 = fig.add_subplot(212)

examples/userdemo/demo_gridspec01.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
def make_ticklabels_invisible(fig):
1111
for i, ax in enumerate(fig.axes):
1212
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
13-
for tl in ax.get_xticklabels() + ax.get_yticklabels():
14-
tl.set_visible(False)
13+
ax.tick_params(labelbottom=False, labelleft=False)
1514

1615

1716
fig = plt.figure(0)

examples/userdemo/demo_gridspec02.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
def make_ticklabels_invisible(fig):
1212
for i, ax in enumerate(fig.axes):
1313
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
14-
for tl in ax.get_xticklabels() + ax.get_yticklabels():
15-
tl.set_visible(False)
14+
ax.tick_params(labelbottom=False, labelleft=False)
1615

1716

1817
fig = plt.figure()

examples/userdemo/demo_gridspec03.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
def make_ticklabels_invisible(fig):
1212
for i, ax in enumerate(fig.axes):
1313
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
14-
for tl in ax.get_xticklabels() + ax.get_yticklabels():
15-
tl.set_visible(False)
14+
ax.tick_params(labelbottom=False, labelleft=False)
1615

1716

1817
# demo 3 : gridspec with subplotpars set.

examples/userdemo/demo_gridspec04.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
def make_ticklabels_invisible(fig):
1212
for i, ax in enumerate(fig.axes):
1313
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
14-
for tl in ax.get_xticklabels() + ax.get_yticklabels():
15-
tl.set_visible(False)
14+
ax.tick_params(labelbottom=False, labelleft=False)
1615

1716

1817
# gridspec inside gridspec

examples/userdemo/demo_gridspec05.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
def make_ticklabels_invisible(fig):
1212
for i, ax in enumerate(fig.axes):
1313
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
14-
for tl in ax.get_xticklabels() + ax.get_yticklabels():
15-
tl.set_visible(False)
14+
ax.tick_params(labelbottom=False, labelleft=False)
1615

1716

1817
f = plt.figure()

tools/make_icons.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,9 @@ def make_matplotlib_icon():
7979
for r, bar in zip(radii, bars):
8080
bar.set_facecolor(cm.jet(r/10.))
8181

82-
for label in ax.get_xticklabels() + ax.get_yticklabels():
83-
label.set_visible(False)
84-
85-
for line in ax.get_ygridlines() + ax.get_xgridlines():
86-
line.set_lw(0.0)
82+
ax.tick_params(labelleft=False, labelright=False,
83+
labelbottom=False, labeltop=False)
84+
ax.grid(lw=0.0)
8785

8886
ax.set_yticks(np.arange(1, 9, 2))
8987
ax.set_rmax(9)

0 commit comments

Comments
 (0)