imshow:将标签作为图像索引的任意函数 [英] imshow: labels as any arbitrary function of the image indices
问题描述
imshow
相对于其列索引(x轴)和行索引(y轴)绘制矩阵.我希望轴标签不是索引,而是索引的任意函数.
imshow
plots a matrix against its column indices (x axis) and row indices (y axis). I would like the axes labels to not be indices, but an arbitrary function of the indices.
例如音调检测
imshow(A, aspect='auto')
其中A.shape == (88200,8)
在x轴上的大约[11000, 22000, ..., 88000]
处显示几个刻度线
在y轴上,显示频率槽[0,1,2,3,4,5,6,7]
in the x-axis, shows several ticks at about [11000, 22000, ..., 88000]
in the y-axis, shows the frequency bin [0,1,2,3,4,5,6,7]
我想要的是:
x轴标记从样本标准化为秒.对于44.1kHz采样率的2秒音频,我想在[1,2]
处打两个勾.
x-axis labeling are normalized from samples to seconds. For a 2 second audio at 44.1kHz sample rate, I want two ticks at [1,2]
.
y轴标记是音高,请注意.我想要标签在音高['c', 'd', 'e', 'f', 'g', 'a', 'b']
的音符中.
y-axis labeling is the pitch as a note. i want the labels in the note of the pitch ['c', 'd', 'e', 'f', 'g', 'a', 'b']
.
理想情况:
imshow(A, ylabel=lambda i: freqs[i], xlabel=lambda j: j/44100)
推荐答案
You can do this with a combination of Locator
s and Formatter
s (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()
这篇关于imshow:将标签作为图像索引的任意函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!