本文整理匯總了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 ''