我有浮動 x/y陣列舉行圈中心。圖像與matplotlib和numpy的圖圈
import matplotlib.pylab as plt
import numpy as np
npX = np.asarray(X)
npY = np.asarray(Y)
plt.imshow(img)
// TO-DO
plt.show()
我想通過使用此中心在我的圖像上顯示圈子。我怎樣才能做到這一點?
我有浮動 x/y陣列舉行圈中心。圖像與matplotlib和numpy的圖圈
import matplotlib.pylab as plt
import numpy as np
npX = np.asarray(X)
npY = np.asarray(Y)
plt.imshow(img)
// TO-DO
plt.show()
我想通過使用此中心在我的圖像上顯示圈子。我怎樣才能做到這一點?
你可以用matplotlib.patches.Circle
補丁來做到這一點。
對於您的示例,我們需要遍歷X和Y數組,然後爲每個座標創建一個圓形補丁。
這裏的放置圓圈上的圖像的頂部(從matplotlib.cbook
)的示例
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Circle
# Get an example image
import matplotlib.cbook as cbook
image_file = cbook.get_sample_data('grace_hopper.png')
img = plt.imread(image_file)
# Make some example data
x = np.random.rand(5)*img.shape[1]
y = np.random.rand(5)*img.shape[0]
# Create a figure. Equal aspect so circles look circular
fig,ax = plt.subplots(1)
ax.set_aspect('equal')
# Show the image
ax.imshow(img)
# Now, loop through coord arrays, and create a circle at each x,y pair
for xx,yy in zip(x,y):
circ = Circle((xx,yy),50)
ax.add_patch(circ)
# Show the image
plt.show()
的可能的複製[繪製與pyplot圓(http://stackoverflow.com/questions/9215658/plot-a-circle-with-pyplot) – kazemakase
你確定嗎?.. – orkan
確實如此。該問題的答案顯示瞭如何繪製圓,這正是你所要求的:) – kazemakase