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

Commit4786a0b

Browse files
authored
Merge pull request#6619 from anntzer/labelouter-hide-labels
ENH: Hide "inner" {x,y}labels in label_outer too.
2 parentsbaf812c +f5c1ab7 commit4786a0b

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

‎examples/pylab_examples/subplots_demo.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,32 @@
2222

2323
# Two subplots, the axes array is 1-d
2424
f,axarr=plt.subplots(2,sharex=True)
25+
f.suptitle('Sharing X axis')
2526
axarr[0].plot(x,y)
26-
axarr[0].set_title('Sharing X axis')
2727
axarr[1].scatter(x,y)
2828

2929
# Two subplots, unpack the axes array immediately
3030
f, (ax1,ax2)=plt.subplots(1,2,sharey=True)
31+
f.suptitle('Sharing Y axis')
3132
ax1.plot(x,y)
32-
ax1.set_title('Sharing Y axis')
3333
ax2.scatter(x,y)
3434

3535
# Three subplots sharing both x/y axes
36-
f, (ax1,ax2,ax3)=plt.subplots(3,sharex=True,sharey=True)
37-
ax1.plot(x,y)
38-
ax1.set_title('Sharing both axes')
39-
ax2.scatter(x,y)
40-
ax3.scatter(x,2*y**2-1,color='r')
41-
# Fine-tune figure; make subplots close to each other and hide x ticks for
42-
# all but bottom plot.
36+
f,axarr=plt.subplots(3,sharex=True,sharey=True)
37+
f.suptitle('Sharing both axes')
38+
axarr[0].plot(x,y)
39+
axarr[1].scatter(x,y)
40+
axarr[2].scatter(x,2*y**2-1,color='r')
41+
# Bring subplots close to each other.
4342
f.subplots_adjust(hspace=0)
44-
plt.setp([a.get_xticklabels()forainf.axes[:-1]],visible=False)
43+
# Hide x labels and tick labels for all but bottom plot.
44+
foraxinaxarr:
45+
ax.label_outer()
4546

4647
# row and column sharing
4748
f, ((ax1,ax2), (ax3,ax4))=plt.subplots(2,2,sharex='col',sharey='row')
49+
f.suptitle('Sharing x per column, y per row')
4850
ax1.plot(x,y)
49-
ax1.set_title('Sharing x per column, y per row')
5051
ax2.scatter(x,y)
5152
ax3.scatter(x,2*y**2-1,color='r')
5253
ax4.plot(x,2*y**2-1,color='r')
@@ -61,9 +62,11 @@
6162
axarr[1,0].set_title('Axis [1,0]')
6263
axarr[1,1].scatter(x,y**2)
6364
axarr[1,1].set_title('Axis [1,1]')
64-
# Fine-tune figure; hide x ticks for top plots and y ticks for right plots
65-
plt.setp([a.get_xticklabels()forainaxarr[0, :]],visible=False)
66-
plt.setp([a.get_yticklabels()forainaxarr[:,1]],visible=False)
65+
foraxinaxarr.flat:
66+
ax.set(xlabel='x-label',ylabel='y-label')
67+
# Hide x labels and tick labels for top plots and y ticks for right plots.
68+
foraxinaxarr.flat:
69+
ax.label_outer()
6770

6871
# Four polar axes
6972
f,axarr=plt.subplots(2,2,subplot_kw=dict(projection='polar'))

‎lib/matplotlib/axes/_subplots.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,25 @@ def is_last_row(self):
125125
defis_last_col(self):
126126
returnself.colNum==self.numCols-1
127127

128-
# COVERAGE NOTE: Never used internally or from examples
128+
# COVERAGE NOTE: Never used internally.
129129
deflabel_outer(self):
130-
"""
131-
set the visible property on ticklabels so xticklabels are
132-
visibleonlyif the subplot is inthe last row and yticklabels
133-
are visible only ifthesubplot is in thefirst column
130+
"""Only show "outer" labels and tick labels.
131+
132+
x-labels areonlykept for subplots onthe last row; y-labels only for
133+
subplots onthe first column.
134134
"""
135135
lastrow=self.is_last_row()
136136
firstcol=self.is_first_col()
137137
forlabelinself.get_xticklabels():
138138
label.set_visible(lastrow)
139139
self.get_xaxis().get_offset_text().set_visible(lastrow)
140+
ifnotlastrow:
141+
self.set_xlabel("")
140142
forlabelinself.get_yticklabels():
141143
label.set_visible(firstcol)
142144
self.get_yaxis().get_offset_text().set_visible(firstcol)
145+
ifnotfirstcol:
146+
self.set_ylabel("")
143147

144148
def_make_twin_axes(self,*kl,**kwargs):
145149
"""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp