这段代码要求用户数字化三个点(使用ginput),然后将这些点绘制到imshow图顶部的屏幕上。事实并非如此。你知道为什么吗?
from pylab import show, ginput, rand, imshow, plot
from matplotlib.figure import Figure
import numpy as np
x1 = rand(103, 53)
figure = Figure(figsize=(4, 4), dpi=100)
axes = figure.add_subplot(111)
imshow(x1)
# Get user input
x = ginput(3)
x = np.array(x)
# Plot the user's points to the screen
plot(x[:, 0], x[:, 1], 'k*', ms=50)
show()发布于 2014-06-03 04:54:31
不确定您正在尝试绘制哪个方向,星和背景,或者反之亦然,但您需要更改调用的顺序。
plot(10, 30, 'k*', ms=100)
x = ginput(2)
imshow(x1)
show()这将显示一颗星,然后当您单击两个点时,显示您的兰德数据。
这是使用取自here的ginput的一个很好的例子
import time
import numpy as np
import matplotlib.pyplot as plt
def tellme(s):
print(s)
plt.title(s,fontsize=16)
plt.draw()
##################################################
# Define a triangle by clicking three points
##################################################
plt.clf()
plt.axis([-1.,1.,-1.,1.])
plt.setp(plt.gca(),autoscale_on=False)
tellme('You will define a triangle, click to begin')
plt.waitforbuttonpress()
happy = False
while not happy:
pts = []
while len(pts) < 3:
tellme('Select 3 corners with mouse')
pts = np.asarray( plt.ginput(3,timeout=-1) )
if len(pts) < 3:
tellme('Too few points, starting over')
time.sleep(1) # Wait a second
ph = plt.fill( pts[:,0], pts[:,1], 'r', lw=2 )
tellme('Happy? Key click for yes, mouse click for no')
happy = plt.waitforbuttonpress()
# Get rid of fill
if not happy:
for p in ph: p.remove()发布于 2015-04-04 08:40:55
您可以在对图像再次执行imshow之前执行关闭操作。
import os, sys
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
im = np.array(Image.open(sys.argv[1]))
plt.imshow(im)
x = plt.ginput(1)
plt.close()
plt.imshow(im)
plt.plot(x[0][0], x[0][1], 'rs')
plt.show()https://stackoverflow.com/questions/24002000
复制相似问题