2

画像の振幅スペクトルを表示したい。次のコードを使用してこれを行うことができます。

import numpy as np
import matplotlib.pyplot as plt
import pylab

pylab.gray()
pic = pylab.imread("C:/pic.png")[::-1,:]
amp_pic = pylab.subplot(1,4,1)
amp_pic.xaxis.set_ticks_position('top')
pylab.imshow(np.abs(np.fft.fftshift(np.fft.fft2(pic))),\
         interpolation='nearest')
pylab.show()

しかし、軸は、振幅スペクトルにラベルを付ける必要がある方法でラベル付けされていません。1D 関数の場合、再ラベル付けはいくらか簡単です。

import math
import numpy as np
import matplotlib.pyplot as plt

array = np.arange(149)
frequency_scale = np.fft.fftfreq(array.shape[0])
function = np.cos(2*math.pi*array/10)
fft = np.fft.fft(function)
amp_fft = np.abs(fft)
plt.subplot(1,4,1)
plt.plot(fkt,'r')
plt.show()

imshow プロットの場合、xaxis に同じラベルが必要です。これは可能ですか?

4

1 に答える 1

4
figure()
im = imshow(rand(500,500))
im.set_extent([0,1,0,1])

set_extentx 軸と y 軸の最大値と最小値を設定します。ドキュメントは次のとおりです。

 |  set_extent(self, extent)
 |      extent is data axes (left, right, bottom, top) for making image plots
 |      
 |      This updates ax.dataLim, and, if autoscaling, sets viewLim
 |      to tightly fit the image, regardless of dataLim.  Autoscaling
 |      state is not changed, so following this with ax.autoscale_view
 |      will redo the autoscaling in accord with dataLim.
于 2012-09-15T18:25:53.403 に答える