From: <jd...@us...> - 2009-06-06 13:26:51
|
Revision: 7185 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7185&view=rev Author: jdh2358 Date: 2009-06-06 13:26:49 +0000 (Sat, 06 Jun 2009) Log Message: ----------- added Neil's auto minor tick patch; sf patch #2789713 Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/pyplot.py trunk/matplotlib/lib/matplotlib/ticker.py Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2009-06-06 11:36:10 UTC (rev 7184) +++ trunk/matplotlib/lib/matplotlib/axes.py 2009-06-06 13:26:49 UTC (rev 7185) @@ -7790,7 +7790,19 @@ return _bbox + def minorticks_on(self): + 'Add autoscaling minor ticks to the axes.' + for ax in (self.xaxis, self.yaxis): + if ax.get_scale() == 'log': + s = ax._scale + ax.set_minor_locator(mticker.LogLocator(s.base, s.subs)) + else: + ax.set_minor_locator(mticker.AutoMinorLocator()) + def minorticks_off(self): + 'Remove minor ticks from the axes.' + self.xaxis.set_minor_locator(mticker.NullLocator()) + self.yaxis.set_minor_locator(mticker.NullLocator()) class SubplotBase: Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2009-06-06 11:36:10 UTC (rev 7184) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2009-06-06 13:26:49 UTC (rev 7185) @@ -1047,8 +1047,23 @@ silent_list('Text yticklabel', labels) ) +def minorticks_on(): + """ + Display minor ticks on the current plot. + Displaying minor ticks reduces performance; turn them off using + minorticks_off() if drawing speed is a problem. + """ + gca().minorticks_on() + draw_if_interactive() +def minorticks_off(): + """ + Remove minor ticks from the current plot. + """ + gca().minorticks_off() + draw_if_interactive() + def rgrids(*args, **kwargs): """ Set/Get the radial locations of the gridlines and ticklabels on a Modified: trunk/matplotlib/lib/matplotlib/ticker.py =================================================================== --- trunk/matplotlib/lib/matplotlib/ticker.py 2009-06-06 11:36:10 UTC (rev 7184) +++ trunk/matplotlib/lib/matplotlib/ticker.py 2009-06-06 13:26:49 UTC (rev 7185) @@ -1182,6 +1182,40 @@ def __init__(self): MaxNLocator.__init__(self, nbins=9, steps=[1, 2, 5, 10]) +class AutoMinorLocator(Locator): + """ + Dynamically find minor tick positions based on the positions of + major ticks. Assumes the scale is linear and major ticks are + evenly spaced. + """ + def __call__(self): + 'Return the locations of the ticks' + majorlocs = self.axis.get_majorticklocs() + try: + majorstep = majorlocs[1] - majorlocs[0] + except IndexError: + raise ValueError('Need at least two major ticks to find minor ' + 'tick locations') + # see whether major step should be divided by 5, 4 or 2. This + # should cover most cases. + temp = float(('%e' % majorstep).split('e')[0]) + if temp % 5 < 1e-10: + minorstep = majorstep / 5. + elif temp % 2 < 1e-10: + minorstep = majorstep / 4. + else: + minorstep = majorstep / 2. + + tmin = majorlocs[0] - majorstep + tmax = majorlocs[-1] + majorstep + locs = np.arange(tmin, tmax, minorstep) + vmin, vmax = self.axis.get_view_interval() + if vmin > vmax: + vmin,vmax = vmax,vmin + + return locs[(vmin < locs) & (locs < vmax)] + + class OldAutoLocator(Locator): """ On autoscale this class picks the best MultipleLocator to set the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |