I have created an image plot with ax = imshow(). ax is an AxesImage object, but I can’t seem to find the function or attribute I need to acess to customize the tick labels. The ordinary pyplots seem to have set_ticks and set_ticklabels methods, but these do not appear to be available for the AxesImage class. Any ideas? Thanks ~
I have created an image plot with ax = imshow() . ax is an
Share
For what it’s worth, you’re slightly misunderstanding what
imshow()returns, and how matplotlib axes are structured in general…An AxesImage object is responsible for the image displayed (e.g. colormaps, data, etc), but not the axis that the image resides in. It has no control over things like ticks and tick labels.
What you want to use is the current axis instance.
You can access this with
gca(), if you’re using thepylabinterface, ormatplotlib.pyplot.gcaif you’re accessing things through pyplot. However, if you’re using either one, there is anxticks()function to get/set the xtick labels and locations.For example (using pylab):
Using a more object-oriented approach (on a random note, matplotlib’s getters and setters get annoying quickly…):
Hope that clears things up a bit!