Skip to content

Commit d09329a

Browse files
committed
turn off redundant tick labeling in pyplot.subplots
svn path=/trunk/matplotlib/; revision=8874
1 parent ebe4529 commit d09329a

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2011-01-03 Turn off tick labeling on interior subplots for
2+
pyplots.subplots when sharex/sharey is True. - JDH
3+
14
2010-12-29 Implment axes_divider.HBox and VBox. -JJL
25

36
2010-11-22 Fixed error with Hammer projection. - BVR

lib/matplotlib/pyplot.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,14 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
684684
Number of columns of the subplot grid. Defaults to 1.
685685
686686
sharex : bool
687-
If True, the X axis will be shared amongst all subplots.
687+
If True, the X axis will be shared amongst all subplots. If
688+
True and you have multiple rows, the x tick labels on all but
689+
the last row of plots will have visible set to False
688690
689-
sharex : bool
690-
If True, the Y axis will be shared amongst all subplots.
691+
sharey : bool
692+
If True, the Y axis will be shared amongst all subplots. If
693+
True and you have multiple columns, the y tick labels on all but
694+
the first column of plots will have visible set to False
691695
692696
squeeze : bool
693697
@@ -760,17 +764,37 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
760764
for i in range(1, nplots):
761765
axarr[i] = fig.add_subplot(nrows, ncols, i+1, **subplot_kw)
762766

767+
768+
769+
# returned axis array will be always 2-d, even if nrows=ncols=1
770+
axarr = axarr.reshape(nrows, ncols)
771+
772+
773+
# turn off redundant tick labeling
774+
if sharex and nrows>1:
775+
# turn off all but the bottom row
776+
for ax in axarr[:-1,:].flat:
777+
for label in ax.get_xticklabels():
778+
label.set_visible(False)
779+
780+
781+
if sharey and ncols>1:
782+
# turn off all but the first column
783+
for ax in axarr[:,1:].flat:
784+
for label in ax.get_yticklabels():
785+
label.set_visible(False)
786+
763787
if squeeze:
764788
# Reshape the array to have the final desired dimension (nrow,ncol),
765789
# though discarding unneeded dimensions that equal 1. If we only have
766790
# one subplot, just return it instead of a 1-element array.
767791
if nplots==1:
768-
return fig, axarr[0]
792+
ret = fig, axarr[0,0]
769793
else:
770-
return fig, axarr.reshape(nrows, ncols).squeeze()
771-
else:
772-
# returned axis array will be always 2-d, even if nrows=ncols=1
773-
return fig, axarr.reshape(nrows, ncols)
794+
ret = fig, axarr.squeeze()
795+
796+
797+
return ret
774798

775799

776800
from gridspec import GridSpec

0 commit comments

Comments
 (0)