2013-06-30 76 views
2

我没有发布整个代码,因为它大部分是不相关的。我只需要帮助中心形象。如何居中绘制的图像?

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是我想要的中心。它正确绘制了所有的图,但情节在左下角。我如何把它放在图形窗口的中间?我需要这个,以便我可以调整缩放的参数。

回答

1

您可以使用extent=(left, right, bottom, top)参数来告诉imshow您想要图像的位置。值leftright, 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() 

产生

enter image description here