1

imshow根据列索引(x 轴)和行索引(y 轴)绘制矩阵。我希望轴标签不是索引,而是索引的任意函数。

例如音高检测

imshow(A, aspect='auto')在哪里A.shape == (88200,8)

在 x 轴上,显示大约[11000, 22000, ..., 88000] 在 y 轴上的几个刻度,显示频率 bin[0,1,2,3,4,5,6,7]

我想要的是:

x 轴标记从样本标准化到秒。对于 44.1kHz 采样率的 2 秒音频,我想要[1,2].

y 轴标注是音高作为音符。我想要音高注释中的标签['c', 'd', 'e', 'f', 'g', 'a', 'b']

理想情况下:

imshow(A, ylabel=lambda i: freqs[i], xlabel=lambda j: j/44100)

4

1 回答 1

1

您可以使用Locators 和Formatters (doc)的组合来执行此操作。

ax = gca()
ax.imshow(rand(500,500))

ax.get_xaxis().set_major_formatter(FuncFormatter(lambda x,p :"%.2f"%(x/44100)))
ax.get_yaxis().set_major_locator(LinearLocator(7))
ax.get_yaxis().set_major_formatter(FixedFormatter(['c', 'd', 'e', 'f', 'g', 'a', 'b']))
draw()
于 2012-09-29T17:31:18.330 回答