[英]How to add a circle to image (figure) in python 2.7?
我在python 2.7中有以下代碼:
import numpy as np
from astropy.io import fits
import matplotlib.pyplot as plt
image_file='test.fits'
hdu_list = fits.open(image_file)
image_data = hdu_list[0].data
plt.imshow(image_data,cmap='gray')
plt.show()
所以我打開了一個FITS文件,並將其數據保存到數組中。
到此為止,沒有任何問題。
現在我有兩個問題。
我的第一個問題是:現在,我想在圖像的特定位置添加一個圓圈(或寫一些文本)。 我的數據是2048 x 2048浮點值的數組。
我的第二個問題是:假設我將此圖形保存(在圖形上/添加任何內容之前)為“ test.png”。 保存為png圖像后,現在我想在png圖像的特定位置添加一個圓圈(或寫一些文本)。 我該怎么做?
任何幫助將不勝感激。 謝謝。
嘗試類似:
hmask,wmask= 0.3,0.3 #radius = 15 pix = 20 AU
m=Ellipse(xy=(0,0),height=hmask,width=wmask)
figure(1).add_subplot(111).add_artist(m)
m.set_color('k')
我有一個類似的問題,並使用了傑羅姆·皮托戈·德萊昂(Jerome Pitogo de Leon)的建議。 就我而言,我有一個bmp圖片,並將其保存到變量'img'中:
import matplotlib.pyplot as plt img = mpimg.imread('img_name.bmp') plt.show()
然后我檢查了軸的外觀,並根據坐標(由目視檢查確定)指定了我的圓
# Define circles
c1 = plt.Circle((100, 600), 50, color=(0, 0, 1))
c2 = plt.Circle((300, 400), 50, color=(1, 0, 0))
c3 = plt.Circle((500, 200), 50, color=(0, 1, 0))
# Open new figure
fig = plt.figure()
# In figure, Image as background
plt.imshow(img)
# Add the circles to figure as subplots
fig.add_subplot(111).add_artist(c1)
fig.add_subplot(111).add_artist(c2)
fig.add_subplot(111).add_artist(c3)
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.