Python matplotlib.pyplot.ginput() Examples
The following are 4
code examples of matplotlib.pyplot.ginput().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.pyplot
, or try the search function
.
Example #1
Source File: strategy.py From ml-five with MIT License | 6 votes |
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
Example #2
Source File: scene_mask.py From kite with GNU General Public License v3.0 | 5 votes |
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)
Example #3
Source File: rrt.py From grammar-activity-prediction with MIT License | 5 votes |
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
Example #4
Source File: zhihu_login.py From zhihu-login with MIT License | 5 votes |
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 ''