我没有发布整个代码,因为大部分代码都不相关。我只需要图像居中的帮助。
ra_new2=cat['ra'][z&lmass&ra&dec][i]
dec_new2=cat['dec'][z&lmass&ra&dec][i]
target_pixel_x = ((ra_new2-ra_ref)/(pixel_size_x))+reference_pixel_x
target_pixel_y = ((dec_new2-dec_ref)/(pixel_size_y))+reference_pixel_y
fig = plt.figure(figsize=(5.,5.))
galaxy=plt.imshow(img[target_pixel_x-200:target_pixel_x+200, target_pixel_y-
200:target_pixel_y+200], vmin=-0.01, vmax=0.1, cmap='Greys')
plt.show()
plt.imshow 是我想要居中的内容。它绘制正确,但绘图位于左下角。我如何将它放在图形窗口的中间?我需要这个以便我可以调整缩放的参数。
请您参考如下方法:
您可以使用 extent=(left, right, bottom, top) 参数来告诉 imshow 您想要图像的位置。值 left、right、bottom、top 在数据坐标中。
例如,
import matplotlib.pyplot as plt
import matplotlib.image as mimage
import matplotlib.cbook as cbook
datafile = cbook.get_sample_data('logo2.png', asfileobj=False)
im = mimage.imread(datafile)
fig, ax = plt.subplots(figsize=(5.,5.))
myaximage = ax.imshow(im,
aspect='auto',
extent=(20, 80, 20, 80),
alpha=0.5)
ax.plot(range(100))
plt.show()
产生
