我试图在网格中绘制多个数字,并标记它们的x和y刻度标记,即:
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()
如何更改这些刻度标签以说明["a", "b", "c", ... "j"]
?
虽然我收到了错误,但我已经尝试了grid[i].set_xtickslabels()
:
AttributeError: 'LocatableAxes' object has no attribute 'set_xtickslabels'
答案 0 :(得分:2)
它是set_xticklabels
,例如:
grid[i].set_xticklabels(["a","b","c"])