[英]How to center a plotted image?
I didn't post the whole code because most of it isn't relevant. 我没有发布整个代码,因为大多数代码都不相关。 I just need help with centering the image.
我只需要帮助使图像居中。
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()
The plt.imshow is what I'm trying to center. plt.imshow是我试图确定的重点。 It plots correctly and all, but the plot is at the bottom left.
它可以正确绘制所有图形,但是该图形位于左下方。 How do I put this in the middle of the graph window?
如何将其放在图形窗口的中间? I need this so that I can adjust the parameters of the zoom.
我需要这样做,以便可以调整缩放参数。
You could use the extent=(left, right, bottom, top)
parameter to tell imshow
where you want the image. 您可以使用
imshow
extent=(left, right, bottom, top)
参数告诉imshow
您想要图像的位置。 The values left
, right
, bottom
, top
are in data-coordinates. left
, right
, bottom
, top
的值在数据坐标中。
For example, 例如,
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()
produces 产生
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.