首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python ginput不允许绘制新点

Python ginput不允许绘制新点
EN

Stack Overflow用户
提问于 2014-06-03 03:40:26
回答 2查看 1.9K关注 0票数 0

这段代码要求用户数字化三个点(使用ginput),然后将这些点绘制到imshow图顶部的屏幕上。事实并非如此。你知道为什么吗?

代码语言:javascript
复制
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()
EN

回答 2

Stack Overflow用户

发布于 2014-06-03 04:54:31

不确定您正在尝试绘制哪个方向,星和背景,或者反之亦然,但您需要更改调用的顺序。

代码语言:javascript
复制
plot(10, 30, 'k*', ms=100)
x = ginput(2)
imshow(x1)

show()

这将显示一颗星,然后当您单击两个点时,显示您的兰德数据。

这是使用取自here的ginput的一个很好的例子

代码语言:javascript
复制
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()
票数 1
EN

Stack Overflow用户

发布于 2015-04-04 08:40:55

您可以在对图像再次执行imshow之前执行关闭操作。

代码语言:javascript
复制
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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24002000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档