本文整理汇总了Python中matplotlib.pyplot.ginput方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.ginput方法的具体用法?Python pyplot.ginput怎么用?Python pyplot.ginput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.ginput方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: preferred_board
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ginput [as 别名]
def preferred_board(self, old, moves, context):
game = context
if game.over:
return
game.wait_human = True
plt.title('set down a stone')
happy = False
while not happy:
pts = np.asarray(plt.ginput(1, timeout=-1, show_clicks=False))
if len(pts) != 1:
continue
i, j = map(round, (pts[0, 0], pts[0, 1]))
loc = int(i * Board.BOARD_SIZE + j)
if old.stones[loc] == Board.STONE_EMPTY:
return [b for b in moves if b.stones[loc] != Board.STONE_EMPTY][0]
else:
plt.title('invalid move')
continue
示例2: click_one_polygon
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ginput [as 别名]
def click_one_polygon(self):
"""
Open a matplotlib window to click a closed polygon to mask.
"""
sc = self.scene
fig = plt.figure()
ax = fig.add_axes([0.05, 0.05, 0.9, 0.9])
ax.imshow(sc.displacement, origin='lower')
ax.set_title('Click to add vertex. Press ENTER to finish.')
# Click polygon to mask
vertices = plt.ginput(-1)
self.add_polygon(vertices)
示例3: select_start_goal_points
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ginput [as 别名]
def select_start_goal_points(ax, img):
print 'Select a starting point'
ax.set_xlabel('Select a starting point')
occupied = True
while occupied:
point = ppl.ginput(1, timeout=-1, show_clicks=False, mouse_pop=2)
start = [int(point[0][0]), int(point[0][1])]
if img[start[1]][start[0]]:
print 'Starting point:', start
occupied = False
ax.plot(start[0], start[1], '.r')
else:
print 'Cannot place a starting point there'
ax.set_xlabel('Cannot place a starting point there, choose another point')
print 'Select a goal point'
ax.set_xlabel('Select a goal point')
occupied = True
while occupied:
point = ppl.ginput(1, timeout=-1, show_clicks=False, mouse_pop=2)
goal = [int(point[0][0]), int(point[0][1])]
if img[goal[1]][goal[0]]:
print 'Goal point:', goal
occupied = False
ax.plot(goal[0], goal[1], '.b')
else:
print 'Cannot place a goal point there'
ax.set_xlabel('Cannot place a goal point there, choose another point')
ppl.draw()
return start, goal
示例4: _get_captcha
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import ginput [as 别名]
def _get_captcha(self, lang: str):
"""
请求验证码的 API 接口,无论是否需要验证码都需要请求一次
如果需要验证码会返回图片的 base64 编码
根据 lang 参数匹配验证码,需要人工输入
:param lang: 返回验证码的语言(en/cn)
:return: 验证码的 POST 参数
"""
if lang == 'cn':
api = 'https://www.zhihu.com/api/v3/oauth/captcha?lang=cn'
else:
api = 'https://www.zhihu.com/api/v3/oauth/captcha?lang=en'
resp = self.session.get(api)
show_captcha = re.search(r'true', resp.text)
if show_captcha:
put_resp = self.session.put(api)
json_data = json.loads(put_resp.text)
img_base64 = json_data['img_base64'].replace(r'\n', '')
with open('./captcha.jpg', 'wb') as f:
f.write(base64.b64decode(img_base64))
img = Image.open('./captcha.jpg')
if lang == 'cn':
import matplotlib.pyplot as plt
plt.imshow(img)
print('点击所有倒立的汉字,在命令行中按回车提交')
points = plt.ginput(7)
capt = json.dumps({'img_size': [200, 44],
'input_points': [[i[0] / 2, i[1] / 2] for i in points]})
else:
img_thread = threading.Thread(target=img.show, daemon=True)
img_thread.start()
# 这里可自行集成验证码识别模块
capt = input('请输入图片里的验证码:')
# 这里必须先把参数 POST 验证码接口
self.session.post(api, data={'input_text': capt})
return capt
return ''