From 3b9c2e0f3002e4ca7769381d5c9c7ca6efd88239 Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Sat, 3 Mar 2012 17:12:19 -0800 Subject: [PATCH 1/2] WIP on ticks based on number of subplots --- CHANGELOG | 3 +++ lib/matplotlib/pyplot.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 45dd72b1fd1c..066c1d68f155 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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. diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index e174b0cb015e..c08d1c6a7ccc 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -897,6 +897,14 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, for label in ax.get_xticklabels(): label.set_visible(False) + if nrows>1: + # scale # of ticks to be based on size how many rows we have + nbins = max(2, 7 - int(nrows)) + #nbins = max(2, int(10/ nrows)) + print(nbins, "y") + for ax in axarr[:,:].flat: + ax.locator_params(axis='y', nbins=nbins) + if sharey and ncols>1: # turn off all but the first column @@ -904,6 +912,13 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, for label in ax.get_yticklabels(): label.set_visible(False) + if ncols>1: + # scale # of ticks to be based on size how many cols we have + nbins = max(2, 7 - int(ncols)) + print(nbins, "x") + for ax in axarr[:,:].flat: + ax.locator_params(axis='x', nbins=nbins) + if squeeze: # Reshape the array to have the final desired dimension (nrow,ncol), # though discarding unneeded dimensions that equal 1. If we only have From f03bdbbb8d9c69aff817f7b94b115bf17ca68e51 Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Tue, 20 Mar 2012 17:26:42 -0700 Subject: [PATCH 2/2] finished ticks based on number of subplots We don't need to adjust every locator when either x- or y-axis is shared across all of the subplots. --- lib/matplotlib/pyplot.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index c08d1c6a7ccc..134289761660 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -884,40 +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) - - if nrows>1: - # scale # of ticks to be based on size how many rows we have - nbins = max(2, 7 - int(nrows)) - #nbins = max(2, int(10/ nrows)) - print(nbins, "y") + elif nrows > 1: + # each y-axis has its own locator for ax in axarr[:,:].flat: - ax.locator_params(axis='y', nbins=nbins) - + 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) - - if ncols>1: - # scale # of ticks to be based on size how many cols we have - nbins = max(2, 7 - int(ncols)) - print(nbins, "x") + elif ncols > 1: + # each y-axis has its own locator for ax in axarr[:,:].flat: - ax.locator_params(axis='x', nbins=nbins) + ax.locator_params(axis='x', nbins=nbins_x) if squeeze: # Reshape the array to have the final desired dimension (nrow,ncol), pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy