⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rectangle_selector.py

📁 非原创。很好的python例子
💻 PY
字号:
"""Do a mouseclick somewhere, move the mouse to some destination, releasethe button.  This class gives click- and release-events and also drawsa line or a box from the click-point to the actual mouseposition(within the same axes) until the button is released.  Within themethod 'self.ignore()' it is checked wether the button from eventpressand eventrelease are the same."""from matplotlib.widgets import RectangleSelectorfrom pylab import subplot, arange, plot, sin, cos, pi, showdef line_select_callback(event1, event2):    'event1 and event2 are the press and release events'    x1, y1 = event1.xdata, event1.ydata    x2, y2 = event2.xdata, event2.ydata    print "(%3.2f, %3.2f) --> (%3.2f, %3.2f)"%(x1,y1,x2,y2)    print " The button you used were: ",event1.button, event2.buttoncurrent_ax=subplot(111)                    # make a new plotingrangeN=100000                                   # If N is large one can see improvementx=10.0*arange(N)/(N-1)                     # by use blitting! plot(x,sin(.2*pi*x),lw=3,c='b',alpha=.7)   # plot somethingplot(x,cos(.2*pi*x),lw=3.5,c='r',alpha=.5)plot(x,-sin(.2*pi*x),lw=3.5,c='g',alpha=.3)    print "\n      click  -->  release"# drawtype is 'box' or 'line' or 'none'LS = RectangleSelector(current_ax, line_select_callback,                      drawtype='box',useblit=True)show()

⌨️ 快捷键说明

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