![](/img/trans.png)
[英]How to put label in Clustering plotted image : indicating in the side which cluster it is, and also in the center?
[英]How to center a plotted 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()
plt.imshow是我試圖確定的重點。 它可以正確繪制所有圖形,但是該圖形位於左下方。 如何將其放在圖形窗口的中間? 我需要這樣做,以便可以調整縮放參數。
您可以使用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()
產生
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.