Skip to content

ticks based on number of subplots #776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
improve settings for these and the ability to pass custom
options. - RMM

2012-03-03 For plt.subplots, the number of ticks depends on number of
subplots. -PI

2012-02-29 errorevery keyword added to errorbar to enable errorbar
subsampling. fixes issue #600.

Expand Down
20 changes: 16 additions & 4 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,25 +884,37 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
for i in range(1, nplots):
axarr[i] = fig.add_subplot(nrows, ncols, i+1, **subplot_kw)



# returned axis array will be always 2-d, even if nrows=ncols=1
axarr = axarr.reshape(nrows, ncols)


# scale # of ticks to be based on how many rows and cols we have
nbins_x = max(2, 7 - int(ncols))
nbins_y = max(2, 7 - int(nrows))

# turn off redundant tick labeling
if sharex and nrows>1:
# when sharing x-axis, the same locator is reused
ax0.locator_params(axis='y', nbins=nbins_y)
# turn off all but the bottom row
for ax in axarr[:-1,:].flat:
for label in ax.get_xticklabels():
label.set_visible(False)

elif nrows > 1:
# each y-axis has its own locator
for ax in axarr[:,:].flat:
ax.locator_params(axis='y', nbins=nbins_y)

if sharey and ncols>1:
# when sharing y-axis, the same locator is reused
ax0.locator_params(axis='x', nbins=nbins_x)
# turn off all but the first column
for ax in axarr[:,1:].flat:
for label in ax.get_yticklabels():
label.set_visible(False)
elif ncols > 1:
# each y-axis has its own locator
for ax in axarr[:,:].flat:
ax.locator_params(axis='x', nbins=nbins_x)

if squeeze:
# Reshape the array to have the final desired dimension (nrow,ncol),
Expand Down