wxpythonのMatplotlibにラバーバンドを表示する
wxpythonでmatplotlibの表示(高速化) - メグタンの何でもブログ の続き
マウスでラバーバンドを表示してmatplotlibの領域を選択したい時
matplotlibにはRectangleSelectorがあるのでそれを利用すると良い。
from matplotlib.widgets import RectangleSelector
# drawtype is 'box' or 'line' or 'none' self.toggle_selector = RectangleSelector(self.ax, self.select_callback, drawtype='box', useblit=True, button=[1], # use left button minspanx=5, minspany=5, spancoords='pixels', interactive=True)
def select_callback(self, eclick, erelease): x0, y0 = eclick.xdata, eclick.ydata x1, y1 = erelease.xdata, erelease.ydata self.p1 = [min(x0, x1), min(y0, y1)] self.p2 = [max(x0, x1), max(y0, y1)] t = 'Select Rect : (%f, %f) (%f, %f)' % (self.p1[0],self.p1[1],self.p2[0],self.p2[1]) self.m_statusBar1.SetStatusText(t)
結果はこんな感じ