gpt4 book ai didi

matplotlib imshow 编辑 x 轴

转载 作者:行者123 更新时间:2023-12-04 18:12:02 24 4
gpt4 key购买 nike

我想显示图像的幅度谱。我可以使用以下代码来做到这一点:

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()

但是轴的标记方式与幅度谱的标记方式不同。在一维函数的情况下,重新标记要容易一些:
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 具有相同的标签。这可能吗?

最佳答案

figure()
im = imshow(rand(500,500))
im.set_extent([0,1,0,1])
set_extent设置 x 和 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.

关于matplotlib imshow 编辑 x 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12425395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com