Scott Warchal
Scott Warchal

Reputation: 1027

Matplotlib LocatableAxes xtick labels

I'm trying to plot multiple figures in a grid, and label their x and y tick marks i.e:

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
import numpy as np


im = np.arange(100)
im.shape = 10, 10

fig = plt.figure(1, (4., 4.))
grid = ImageGrid(fig, 111,  # similar to subplot(111)
                 nrows_ncols=(2, 2),  # creates 2x2 grid of axes
                 axes_pad=0.1,  # pad between axes in inch.
                 )

for i in range(4):
    grid[i].imshow(im)  # The AxesGrid object work as a list of axes.
    grid[i].set_xticks(np.arange(im.shape[0]))
    grid[i].set_yticks(np.arange(im.shape[0]))

plt.show()

enter image description here .

How would I change these tick labels to say ["a", "b", "c", ... "j"]?

I've tried grid[i].set_xtickslabels() though I get the error:
AttributeError: 'LocatableAxes' object has no attribute 'set_xtickslabels'

Upvotes: 1

Views: 817

Answers (1)

decvalts
decvalts

Reputation: 753

It's set_xticklabels, e.g.:

grid[i].set_xticklabels(["a","b","c"])

Upvotes: 2

Related Questions