def __init__(self, ax, x1, x2, bounds=None, slide_on='x', valfmt='%1.2f', closedmin=True, closedmax=True, dragging=True, use_blit=True, **kwargs): self.ax = ax #AxesWidget.__init__(self, ax) #NOTE: sets self.ax, self.canvas etc self.slide_on = slide_on self._index = int(slide_on == 'y') self._locked = 'yx'[self._index] self._order = slice(None, None, -1 if self._index else 1) self.axpos = ax.viewLim.get_points()[int(not self._index), 0]#1.0 #set the axis spine position #TODO: more descriptive name for this thing #print(ax.get_xlim(), ax.get_ylim()) self.setup_axes(ax) #ax2data = ax.transAxes + ax.transData.inverted() #initial values #self.positions = np.array([x1, x2]) #x1, x2 = vals self._original_position = np.array([x1, x2]) #set the bounds #IS THIS EXPLICITLY NECESSARY?? self._bounds = bounds if bounds is not None: self._bounds = sorted(bounds) #transform position of sliders form data to axes coordinates #val_ax = [x1, x2] / (self.valmax - self.valmin) self.dragging = dragging #create sliders & add to axis ms = self.marker_size coo1 = [x1, self.axpos][self._order] coo2 = [x2, self.axpos][self._order] #transform = btf(*[ax.transAxes, ax.transData][self._order]) markers = ax.plot(*coo1, 'b>', *coo2, 'r<', #note: python3.5 syntax only ms=ms, picker=15, clip_on=False,) #plot to outside axes #transform=transform) #self.sliders = [self.min_slider, self.max_slider] #self.valfmt = valfmt DragMachinery.__init__(self, markers, annotate=False) self.sliders = self.min_slide, self.max_slide = list(self) for slide in self.sliders: slide.lock(self._locked) opg = operator.ge if closedmin else operator.gt self.min_slide.validation(lambda xy: opg(xy[self._index], self.boundmin)) self.min_slide.validation(lambda xy: xy[self._index] < self.positions[1]) opl = operator.le if closedmax else operator.lt self.max_slide.validation(lambda xy: opl(xy[self._index], self.boundmax)) self.max_slide.validation(lambda xy: xy[self._index] > self.positions[0])
from draggables.machinery import DragMachinery from draggables.errorbar import DraggableErrorbar from draggables.lines import DragggableLine #Line2D test x = 0 #np.arange(N) y0 = 0.5 #np.random.randn(N) fig, ax = plt.subplots( figsize=(18,8) ) pl = ax.plot(x, y0, 'r>', clip_on=False) ax.set_xlim(0, 0.5) d = DragMachinery(pl) d.connect() plt.show(block=False) #Errorbar test #fig, ax = plt.subplots( figsize=(18,8) ) #N = 100 #x = np.arange(N) #y0 = np.random.randn(N) #y1, y2, y3 = y0 + np.c_[[5, 10, -10]] #y0err, y1err = np.random.randn(2, N) / np.c_[[5, 2]] #y2err, y3err = None, None #x0err, x1err, x2err, x3err = np.random.randn(N), None, None, np.random.randn(N)*8