On 3/11/12 8:14 AM, cgraves wrote: > > Hi, here is an example script which places minor ticks with 2 per major tick > (minor tick spacing is "fractional" of major tick spacing with relative > interval of 1/2): > > from pylab import * > fig=figure() > ax=subplot(111) > ax.autoscale(tight=True) > plot([1,2,4],[1,2,3]) > x_ticks_maj_spacing = > float(abs(ax.xaxis.get_ticklocs()[0]-ax.xaxis.get_ticklocs()[1])) > x_ticks_min_spacing = x_ticks_maj_spacing/2 > ax.xaxis.set_minor_locator(MultipleLocator(x_ticks_min_spacing)) > y_ticks_maj_spacing = > float(abs(ax.yaxis.get_ticklocs()[0]-ax.yaxis.get_ticklocs()[1])) > y_ticks_min_spacing = y_ticks_maj_spacing/2 > ax.yaxis.set_minor_locator(MultipleLocator(y_ticks_min_spacing)) > show() > > This works fine. However, if one changes the axes limits then the major > ticks get automatically adjusted to a different interval but the minor ticks > remain at the positions they were already at. To see this, either use the > zoom tools or do the following after running the above: > > xlim(1,2.5) > fig.canvas.draw() > > The question is, what is the best way to maintain the fractional minor tick > spacing? I suppose one could set up a way to update the set_minor_locator > and redraw the figure each time the figure axes limits are adjusted, but is > there a better way?
Try this: from pylab import * from matplotlib.ticker import AutoMinorLocator clf() ax=subplot(111) ax.autoscale(tight=True) plot([1,2,4],[1,2,3]) ax.xaxis.set_minor_locator(AutoMinorLocator(2)) ax.yaxis.set_minor_locator(AutoMinorLocator(2)) draw() M PS: I believe this is a fairly new feature... ------------------------------------------------------------------------------ Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users