Locator tick_values for images #7775

larrybradley opened this Issue Jan 9, 2017 · 1 comment


None yet

2 participants


While investigating #7774, I noticed one other issue. When used with images, the locator tick_values method returns limits outside of the image bounds.


>>> data = np.arange(100).reshape(10, 10)
>>> fig, ax = plt.subplots()
>>> ax.imshow(data)
>>> x0, x1 = ax.dataLim.intervalx
>>> print(x0, x1)
-0.5 9.5

Those are the the correct image bounds because integer indices represent the center of pixels. However, this is puzzling:

>>> xlocator = ax.xaxis.get_major_locator()
>>> xlocator.tick_values(x0, x1)
array([ -2.,   0.,   2.,   4.,   6.,   8.,  10.])

>>> xlocator.view_limits(x0, x1)
array([ -2.,  10.])

I assume this is because it is trying to include the "values" -0.5 and 9.5, but the tick values -2 and 10 don't make much sense since they are outside of the image bounds. I would have expected array([ 0., 2., 4., 6., 8.]), which is what is actually plotted.

efiring commented Jan 9, 2017

tick_values overshoots because it is used in autoscaling. Depending on whether "round number" limits are requested, ticks beyond the data range may be needed. When they aren't, they are discarded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment