I'm not sure exactly how you want your minor ticks, but you can try this
LinearMinorLocator (which is not in the distribution yet).
If you're conversant with git you can find the branch here:
https://github.com/matplotlib/matplotlib/pull/122
M
On 6/19/11 3:20 PM, matplotlib.coral...@xoxy.net wrote:
I am having trouble adding minor tick marks to an auto-scaled axis on
a linear plot. I hope someone can help.
I am drawing a plot where the X axis values are predictable, so I
have the ability to define the desired major/minor intervals for
tickmarks and gridlines. The scale of the X axis is automatically
defined by matplotlib. I have manually specified the major and minor
X axis tick/grid intervals using:
plt.grid(True, which='both') XmajorLocator XmajorFormatter
XminorLocator
My Y axis values are not predictable, so I rely on matplotlib to
autoscale the Y axis, automatically defining the total range of
values plotted and the major tickmark& gridline intervals. I need
more gridline resolution, so I would like to be able to add minor
gridlines to the automatically scaled Y axis, but I'm having trouble
doing it.
At present the autoscaled Y axis is only producing major ticks and
major gridlines. I'd like to add minor ticks and gridlines, but I
have not been successful so far. I'm hoping that someone can point
out an obvious solution that I've just overlooked. TIA.
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________ Matplotlib-users
mailing list Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
from matplotlib.ticker import *
class LinearMinorLocator(Locator):
"""
Set fixed number of minor ticks between each major tick.
Assumes the scale is linear and major ticks are evenly spaced.
"""
def __init__(self, numticks):
"'numticks' is the number of minor ticks between each major tick."
self.numticks = numticks
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')
# divide the major step into numticks+1 intervals
minorstep = majorstep / (self.numticks + 1)
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
locs = locs[(vmin < locs) & (locs < vmax)]
# don't create minor ticks on top of existing major ticks
diff = 0.5 * abs(locs[1] - locs[0])
locs = [l for l in locs if (np.abs(l - majorlocs) > diff).all()]
return self.raise_if_exceeds(np.array(locs))
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users