【问题标题】:Matplotlib LocatableAxes xtick labelsMatplotlib LocatableAxes xtick 标签
【发布时间】:2017-01-20 12:17:33
【问题描述】:

我正在尝试在网格中绘制多个图形,并标记它们的 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'

【问题讨论】:

  • 你错了正确的方法名是set_xticklabels

标签: python matplotlib


【解决方案1】:

set_xticklabels,例如:

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

【讨论】:

  • 那太愚蠢了。
猜你喜欢
  • 2017-02-02
  • 2014-07-25
  • 2016-07-24
  • 1970-01-01
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 2017-08-06
  • 1970-01-01
相关资源
最近更新 更多