picker_demo.py

来自「非原创。很好的python例子」· Python 代码 · 共 52 行

PY
52
字号
#!/usr/bin/env python"""Hold the pointer over an object and press "p" to pick it.  Whenpicked it will turn red Note this algorithm calculates distance to the vertices of thepolygon, so if you want to pick a patch, click on the edge!"""from pylab import *from matplotlib.text import Textfrom matplotlib.lines import Line2Dfrom matplotlib.patches import Patchdef pick(event):    if event.key=='p' and event.inaxes is not None:        ax = event.inaxes        a = ax.pick(event.x, event.y)        	if isinstance(a, Text):            a.set_color('r')        elif isinstance(a, Line2D):            a.set_markerfacecolor('r')	elif isinstance(a, Patch):            a.set_facecolor('r')        draw()                connect('key_press_event', pick)ax = subplot(111)title('Put mouse over object and press "p" to pick it')for i in range(20):    x, y = rand(2)    text(x,y,'hi!')for i in range(5):    x = rand(10)    y = rand(10)    plot(x,y,'go')for i in range(5):    x = rand()    y = rand()    center = x,y    p = Circle(center, radius=.1)    ax.add_patch(p)    show()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?