Ejemplo n.º 1
0
    def __init__(self, ax, onselect, useblit=False, button=None,
                 state_modifier_keys=None):
        AxesWidget.__init__(self, ax)

        self.visible = True
        self.onselect = onselect
        self.useblit = useblit and self.canvas.supports_blit
        self.connect_default_events()

        self.state_modifier_keys = dict(move=' ', clear='escape',
                                        square='shift', center='control')
        self.state_modifier_keys.update(state_modifier_keys or {})

        self.background = None
        self.artists = []

        if isinstance(button, int):
            self.validButtons = [button]
        else:
            self.validButtons = button

        # will save the data (position at mouseclick)
        self.eventpress = None
        # will save the data (pos. at mouserelease)
        self.eventrelease = None
        self._prev_event = None
        self.state = set()
Ejemplo n.º 2
0
    def __init__(self, ax, name, data, wdlength, min_wdlength):
        """
        Create a slider from *valmin* to *valmax* in axes *ax*

        """
        AxesWidget.__init__(self, ax)
        self.wdlength = wdlength
        self.min_wdlength = min_wdlength
        self.voffset = 0
        self.xmax = len(data)
        self.xmin = max(0, self.xmax-self.wdlength) 
        self.ymax = np.max(data.high[self.xmin : self.xmax].values) + self.voffset
        self.ymin = np.min(data.low[self.xmin : self.xmax].values) - self.voffset
        self.ax = ax
        self.cnt = 0
        self.observers = {}
        self.data = data
        self.name = name

        ax.set_xlim((self.xmin, self.xmax))
        ax.set_ylim((self.ymin, self.ymax))
        self.a1, self.a2 = candlestick2(ax, data.open.tolist()[:self.xmax], data.close.tolist()[:self.xmax], 
                                        data.high.tolist()[:self.xmax], data.low.tolist()[:self.xmax], 
                                        0.6, 'r', 'g')
        self.connect_event('key_release_event', self.keyrelease)
Ejemplo n.º 3
0
    def __init__(self, ax, label, image=None,
             color='0.85', hovercolor='0.95'):
        AxesWidget.__init__(self, ax)

        if image is not None:
            ax.imshow(image)
        self.label = ax.text(0.5, 0.5, label,
                             verticalalignment='center',
                             horizontalalignment='center',
                             transform=ax.transAxes)

        self.cnt = 0
        self.observers = {}

        self.connect_event('button_press_event', self._click)
        self.connect_event('button_release_event', self._release)
        self.connect_event('motion_notify_event', self._motion)
        ax.set_navigate(False)
        ax.set_axis_bgcolor(color)
        ax.set_xticks([])
        ax.set_yticks([])
        # self.ax.spines['top'].set_visible(False)
        # self.ax.spines['right'].set_visible(False)
        # self.ax.spines['bottom'].set_visible(False)
        # self.ax.spines['left'].set_visible(False)
        self.color = color
        self.hovercolor = hovercolor

        self._lastcolor = color
Ejemplo n.º 4
0
    def __init__(self, ax, scrollbarSize=1.0, thumbSize=0.3, position=0.0, callback=None):
        AxesWidget.__init__(self, ax)

        self.ax = ax
        self.ax.get_xaxis().set_visible(False)
        self.ax.get_yaxis().set_visible(False)
        self.ax.set_ylim((0, scrollbarSize + thumbSize))

        self.scrollbarSize = scrollbarSize
        self.scrollPage = (self.scrollbarSize / 20)
        self.thumbSize = thumbSize
        self.position = position

        self.callback = callback

        xx = self.ax.get_xlim()
        width = xx[1]-xx[0]
        height = self.thumbSize

        self.thumb = patches.Rectangle((xx[0], self.position), width, height, alpha=1.0, color='gray')
        self.ax.add_patch(self.thumb)
        self.bbox = self.thumb.get_bbox()

        self.drag_active = False
        self.drag_startY = 0

        self.ax.edgecolor = 'blue'
        self.ax.set_facecolor('0.90')

        self.connect_event('button_press_event', self.onPress)
        self.connect_event('button_release_event', self.onRelease)
        self.connect_event('motion_notify_event', self.onMotion)
Ejemplo n.º 5
0
    def __init__(self,
                 ax,
                 horizOn=True,
                 vertOn=True,
                 useblit=False,
                 **lineprops):
        """
        Add a cursor to *ax*.  If ``useblit=True``, use the backend-
        dependent blitting features for faster updates (GTKAgg
        only for now).  *lineprops* is a dictionary of line properties.

        .. plot :: mpl_examples/widgets/cursor.py
        """
        # TODO: Is the GTKAgg limitation still true?
        AxesWidget.__init__(self, ax)

        self.connect_event('motion_notify_event', self.onmove)
        self.connect_event('draw_event', self.clear)

        self.visible = True
        self.horizOn = horizOn
        self.vertOn = vertOn
        self.useblit = useblit and self.canvas.supports_blit
        self.moved = False

        if self.useblit:
            lineprops['animated'] = True
        self.lineh = ax.axhline(ax.get_ybound()[0], visible=False, **lineprops)
        self.linev = ax.axvline(ax.get_xbound()[0], visible=False, **lineprops)

        self.background = None
        self.needclear = False
Ejemplo n.º 6
0
    def __init__(self, ax, labels, active=0, activecolor='blue'):
        """
        Add radio buttons to :class:`matplotlib.axes.Axes` instance *ax*
        *labels*
            A len(buttons) list of labels as strings
        *active*
            The index into labels for the button that is active
        *activecolor*
            The color of the button when clicked
        """
        AxesWidget.__init__(self, ax)
        self.activecolor = activecolor
        self.value_selected = None

        ax.set_xticks([])
        ax.set_yticks([])
        ax.set_navigate(False)
        dy = 1. / (len(labels) + 1)
        ys = np.linspace(1 - dy, dy, len(labels))
        cnt = 0
        axcolor = ax.get_facecolor()

        # scale the radius of the circle with the spacing between each one
        circle_radius = (dy / 2) - 0.01

        # defaul to hard-coded value if the radius becomes too large
        if (circle_radius > 0.05):
            circle_radius = 0.05

        self.labels = []
        self.circles = []
        for y, label in zip(ys, labels):
            t = ax.text(0.25,
                        y,
                        label,
                        transform=ax.transAxes,
                        horizontalalignment='left',
                        verticalalignment='center')

            if cnt == active:
                self.value_selected = label
                facecolor = activecolor
            else:
                facecolor = axcolor

            p = Circle(xy=(0.15, y),
                       radius=circle_radius,
                       edgecolor='black',
                       facecolor=facecolor,
                       transform=ax.transAxes)

            self.labels.append(t)
            self.circles.append(p)
            ax.add_patch(p)
            cnt += 1

        self.connect_event('button_press_event', self._clicked)

        self.cnt = 0
        self.observers = {}
Ejemplo n.º 7
0
    def __init__(self, ax, is_closed=False, max_points=None,
                 line_kw=None, circle_kw=None):
        AxesWidget.__init__(self, ax)
        self.visible = True

        self.observers = {}
        self.release_observers = {}
        self.cid = 0

        self.xs = []
        self.ys = []
        kw = line_kw if line_kw is not None else {}
        self.line = Line2D(self.xs, self.ys, **kw)
        self.ax.add_artist(self.line)

        self.circle_kw = dict(radius=5, alpha=0.5)
        if circle_kw:
            self.circle_kw.update(circle_kw)

        self.circles = []

        self.is_closed = is_closed
        self.max_points = max_points

        self.moving_ci = None

        self.connect_event('button_press_event', self._press)
        self.connect_event('button_release_event', self._release)
        self.connect_event('motion_notify_event', self._motion)
Ejemplo n.º 8
0
    def __init__(self,
                 ax,
                 labels,
                 active=0,
                 activecolor='blue',
                 size=49,
                 orientation="vertical",
                 **kwargs):
        """
        Add radio buttons to an `~.axes.Axes`.
        Parameters
        ----------
        ax : `~matplotlib.axes.Axes`
            The axes to add the buttons to.
        labels : list of str
            The button labels.
        active : int
            The index of the initially selected button.
        activecolor : color
            The color of the selected button.
        size : float
            Size of the radio buttons
        orientation : str
            The orientation of the buttons: 'vertical' (default), or 'horizontal'.
        Further parameters are passed on to `Legend`.
        """
        AxesWidget.__init__(self, ax)
        self.activecolor = activecolor
        axcolor = ax.get_facecolor()
        self.value_selected = None

        ax.set_xticks([])
        ax.set_yticks([])
        ax.set_navigate(False)

        circles = []
        for i, label in enumerate(labels):
            if i == active:
                self.value_selected = label
                facecolor = activecolor
            else:
                facecolor = axcolor
            p = ax.scatter([], [],
                           s=size,
                           marker="o",
                           edgecolor='black',
                           facecolor=facecolor)
            circles.append(p)
        if orientation == "horizontal":
            kwargs.update(ncol=len(labels), mode="expand")
        kwargs.setdefault("frameon", False)
        self.box = ax.legend(circles, labels, loc="center", **kwargs)
        self.labels = self.box.texts
        self.circles = self.box.legendHandles
        for c in self.circles:
            c.set_picker(5)
        self.cnt = 0
        self.observers = {}

        self.connect_event('pick_event', self._clicked)
Ejemplo n.º 9
0
    def __init__(self, ax, name, data, wdlength, min_wdlength):
        """
        Create a slider from *valmin* to *valmax* in axes *ax*

        """
        AxesWidget.__init__(self, ax)
        self.wdlength = wdlength
        self.min_wdlength = min_wdlength
        self.voffset = 0
        self.xmax = len(data)
        self.xmin = max(0, self.xmax - self.wdlength)
        self.ymax = np.max(
            data.high[self.xmin:self.xmax].values) + self.voffset
        self.ymin = np.min(data.low[self.xmin:self.xmax].values) - self.voffset
        self.ax = ax
        self.cnt = 0
        self.observers = {}
        self.data = data
        self.name = name

        ax.set_xlim((self.xmin, self.xmax))
        ax.set_ylim((self.ymin, self.ymax))
        self.a1, self.a2 = candlestick2(ax,
                                        data.open.tolist()[:self.xmax],
                                        data.close.tolist()[:self.xmax],
                                        data.high.tolist()[:self.xmax],
                                        data.low.tolist()[:self.xmax], 0.6,
                                        'r', 'g')
        self.connect_event('key_release_event', self.keyrelease)
Ejemplo n.º 10
0
    def __init__(self, ax,
                 is_closed=False, max_points=None, grows=True, shrinks=True,
                 line_kw=None, circle_kw=None):
        AxesWidget.__init__(self, ax)
        Actionable.__init__(self)
        self.visible = True

        self.observers = {}
        self.release_observers = {}
        self.cid = 0

        self.xs = []
        self.ys = []
        kw = line_kw if line_kw is not None else {}
        self.line, = self.ax.plot(self.xs, self.ys, **kw)

        self.circle_kw = circle_kw if circle_kw is not None else {}

        self.circles = []

        self.moving_ci = None

        self.is_closed = is_closed
        self.max_points = max_points

        self._lclick_cids = None
        self.grows = grows

        self._rclick_cids = None
        self._can_shrink = False
        self.shrinks = shrinks

        self.connect_event('button_press_event', self._left_press),
        self.connect_event('button_release_event', self._release),
        self.connect_event('motion_notify_event', self._motion),
Ejemplo n.º 11
0
    def __init__(
        self,
        parent,
        useblit=False,
        snapDist=5,
        snapType={
            'Segments': False,
            'SegmentEnds': False,
            'Origin': True,
            'Grid': True,
            'Centers': True
        }):
        self.parent = parent
        self.doc = self.parent.doc
        self.ax = self.parent.plt
        self.canvas = self.parent.canvas
        self.snapDist = snapDist
        self.snapType = self.setSnapType(snapType)
        SnaptoCursor.snapping = False

        AxesWidget.__init__(self, self.ax)

        self.connect_event('motion_notify_event', self.onmove)
        self.connect_event('draw_event', self.clear)

        self.useblit = useblit and self.canvas.supports_blit

        self.cursor, = self.ax.plot(0, 0, 'rx', animated=self.useblit)
        self.cursor.set_visible(False)
        self.visible = True

        self.background = None
        self.needclear = False
Ejemplo n.º 12
0
    def __init__(self, ax, s='', allowed_chars=None, type=str, **text_kwargs):
        AxesWidget.__init__(self, ax)
        self.ax.set_navigate(False)
        self.ax.set_yticks([])
        self.ax.set_xticks([])

        self.type = type
        self.allowed_chars = allowed_chars
        self.value = self.type(s)
        self.text = self.ax.text(0.025,
                                 0.2,
                                 s,
                                 transform=self.ax.transAxes,
                                 **text_kwargs)

        self._cid = None
        self._cursor = None
        self._cursorpos = len(self.text.get_text())
        self.old_callbacks = {}

        self.cnt = 0
        self.observers = {}

        self.exit_cnt = 0
        self.exit_observers = {}

        self.connect_event('button_press_event', self._mouse_activate)
Ejemplo n.º 13
0
    def __init__(self,
                 ax,
                 labels,
                 marker='$-$',
                 keep_color=False,
                 size=49,
                 orientation="vertical",
                 **kwargs):
        """
        Add radio buttons to an `~.axes.Axes`.
        Parameters
        ----------
        ax : `~matplotlib.axes.Axes`
            The axes to add the buttons to.
        labels : list of str
            The button labels...
        marker : str
            Changes can be made according to matplotlib.markers selection
        keep_color : Bool
            if True button press does nothing else button color turns on/off
        size : float
            Size of the radio buttons
        orientation : str
            The orientation of the buttons: 'vertical' (default), or 'horizontal'.
        Further parameters are passed on to `Legend`.
        """
        AxesWidget.__init__(self, ax)
        self.value_selected = None
        self.keep_color = keep_color

        ax.set_xticks([])
        ax.set_yticks([])
        ax.set_navigate(False)

        self.circles = []
        for i, label in enumerate(labels):
            if i:
                self.value_selected = label
                facecolor = 'C' + str(i % 10)
            else:
                facecolor = 'C' + str(i % 10)
            p = ax.scatter([], [],
                           s=size,
                           marker=marker,
                           edgecolor='black',
                           facecolor=facecolor)
            self.circles.append(p)
        if orientation == "horizontal":
            kwargs.update(ncol=len(labels), mode="expand")
        kwargs.setdefault("frameon", False)
        self.box = ax.legend(self.circles, labels, loc="center", **kwargs)
        self.labels = self.box.texts
        self.circles = self.box.legendHandles
        for c in self.circles:
            c.set_picker(5)
        self.cnt = 0
        self.observers = {}

        self.connect_event('pick_event', self._clicked)
Ejemplo n.º 14
0
    def __init__(self, ax, txt):
        AxesWidget.__init__(self, ax)

        self.t = txt
        self.connect_event('button_press_event', self._clicked)
        self._prev_color = ''
        self.cnt = 0
        self.observers = {}
        ax.set_navigate(False)
Ejemplo n.º 15
0
    def __init__(self, ax, callback=None, useblit=True):
        AxesWidget.__init__(self, ax)

        self.useblit = useblit and self.canvas.supports_blit
        self.verts = []
        self.drawing = False
        self.line = None
        self.callback = callback
        self.last_click_time = time.time()
        self.connect_event('button_press_event', self.onpress)
        self.connect_event('motion_notify_event', self.onmove)
Ejemplo n.º 16
0
    def __init__(self, ax, callback=None, useblit=True):
        AxesWidget.__init__(self, ax)

        self.useblit = useblit and self.canvas.supports_blit
        self.verts = []
        self.drawing = False
        self.line = None
        self.callback = callback
        self.last_click_time = time.time()
        self.connect_event('button_press_event', self.onpress)
        self.connect_event('motion_notify_event', self.onmove)
Ejemplo n.º 17
0
    def __init__(self, ax, pos, **kwargs):
        AxesWidget.__init__(self, ax)

        self.cursor = Cursor(ax, useblit=True, **kwargs)

        self.connect_event('button_press_event', self._update)
        self.connect_event('button_release_event', self._update)
        self.cnt = 0
        self.observers = {}
        self.drag_active = False
        self.pos = pos
Ejemplo n.º 18
0
    def __init__(self, vertex_list, ax, channels, name=None):
        AxesWidget.__init__(self, ax)
        self.channels = channels
        self.name = name
        self.region = '?'
        self.gate_type = self.__class__.__name__

        self._spawned_vertex_list = [vert.spawn(self.ax, channels) for vert in vertex_list]
        [svertex.add_callback(self.handle_vertex_event) for svertex in self._spawned_vertex_list]
        self.create_artist()
        self.activate()
Ejemplo n.º 19
0
    def __init__(self, vertex_list, ax, channels, name=None):
        AxesWidget.__init__(self, ax)
        self.channels = channels
        self.name = name
        self.region = '?'
        self.gate_type = self.__class__.__name__

        self._spawned_vertex_list = [vert.spawn(self.ax, channels) for vert in vertex_list]
        [svertex.add_callback(self.handle_vertex_event) for svertex in self._spawned_vertex_list]
        self.create_artist()
        self.activate()
Ejemplo n.º 20
0
    def __init__(self, ax, lineprops=None, **kwargs):
        """
        Add a bar to *ax*.  *lineprops* is a dictionary of line properties.
        """
        AxesWidget.__init__(self, ax)
        if lineprops is None:
            lineprops = dict(color='#e66101', lw=2)

        self.linev = ax.axvline(0, 0, 1, visible=False, **lineprops)
        self.background = None
        self.needclear = False
        self.connect_event('draw_event', self.clear)
Ejemplo n.º 21
0
    def __init__(self, ax, pixels):
        AxesWidget.__init__(self, ax)
        self.pixels = pixels
        self.image = self.ax.imshow(self.pixels,
                                    aspect='auto',
                                    interpolation='none',
                                    vmin=0,
                                    vmax=1)
        self.l = None

        self.observers = {}
        self.cid = 0
Ejemplo n.º 22
0
    def __init__(self,
                 ax,
                 x,
                 y,
                 horizOn=True,
                 vertOn=True,
                 useblit=False,
                 **lineprops):
        AxesWidget.__init__(self, ax)

        self.connect_event('motion_notify_event', self.onmove)
        self.connect_event('button_press_event', self.onclick)
        self.connect_event('draw_event', self.clear)

        self.visible = True
        self.horizOn = horizOn
        self.vertOn = vertOn
        self.useblit = useblit and self.canvas.supports_blit

        if self.useblit:
            lineprops['animated'] = True
        self.lineh = ax.axhline(ax.get_ybound()[0], visible=False, **lineprops)
        self.linev = ax.axvline(ax.get_xbound()[0], visible=False, **lineprops)

        self.marker, = ax.plot(0,
                               0,
                               marker='o',
                               visible=False,
                               color='red',
                               markersize=4)

        self.background = None
        self.needclear = False

        self.x = x
        self.y = y
        # text location in axes coords
        self.txt = ax.text(0.25,
                           0.95,
                           '',
                           transform=ax.transAxes,
                           bbox=dict(boxstyle="round",
                                     ec=(1., 0.5, 0.5),
                                     fc=(1., 0.8, 0.8)))
        self.gradtxt = ax.text(0.25,
                               0.8,
                               '',
                               transform=ax.transAxes,
                               bbox=dict(boxstyle="round",
                                         ec=(1., 0.5, 0.5),
                                         fc=(1., 0.8, 0.8)))
        self.positions = []
        self.lines = []
    def __init__(self, ax, radius, **circprops):
        AxesWidget.__init__(self, ax)

        self.connect_event('motion_notify_event', self.onmove)
        self.connect_event('draw_event', self.storebg)

        circprops['animated'] = True
        circprops['radius'] = radius

        self.circ = plt.Circle((0,0), **circprops)
        self.ax.add_artist(self.circ)

        self.background = None
Ejemplo n.º 24
0
    def __init__(self, ax, radius, **circprops):
        AxesWidget.__init__(self, ax)

        self.connect_event('motion_notify_event', self.onmove)
        self.connect_event('draw_event', self.storebg)

        circprops['animated'] = True
        circprops['radius'] = radius

        self.circ = plt.Circle((0, 0), **circprops)
        self.ax.add_artist(self.circ)

        self.background = None
Ejemplo n.º 25
0
    def __init__(self, ax, pixels):
        AxesWidget.__init__(self, ax)
        Actionable.__init__(self)
        self.pixels = pixels
        self.image = self.ax.imshow(self.pixels,
                                    aspect='auto',
                                    interpolation='none',
                                    vmin=0,
                                    vmax=1)
        self.l = None

        self.observers = {}
        self.cid = 0
Ejemplo n.º 26
0
    def __init__(self,
                 ax,
                 track_x=True,
                 track_y=True,
                 show_coord=True,
                 text_format="(%.2f, %.2f)",
                 col='green',
                 useblit=True,
                 show_drag=False,
                 **lineprops):
        AxesWidget.__init__(self, ax)

        self.connect_event('motion_notify_event', self.onmove)
        self.connect_event('draw_event', self.clear)
        if show_drag:
            self.connect_event('button_press_event', self.on_press)
            self.connect_event('button_release_event', self.on_release)

        self.visible = True
        self.horizOn = track_y
        self.vertOn = track_x
        self.drag_on = show_drag
        self.show_coord = show_coord
        self.text_format = text_format
        self.useblit = useblit and self.canvas.supports_blit

        if self.useblit:
            lineprops['animated'] = True
        if 'color' not in lineprops:
            lineprops['color'] = col
        self.lineh = ax.axhline(ax.get_ybound()[0], visible=False, **lineprops)
        self.linev = ax.axvline(ax.get_xbound()[0], visible=False, **lineprops)
        self.text = ax.text(ax.get_xbound()[0],
                            ax.get_ybound()[0],
                            '',
                            fontsize=8,
                            color=col,
                            visible=False)
        self.area = patches.Rectangle((0, 0),
                                      0,
                                      0,
                                      fc=col,
                                      ec=None,
                                      alpha=0.2,
                                      visible=False)
        self.ax.add_patch(self.area)

        self._press = None
        self.background = None
        self.needclear = False
    def __init__(self, ax, label, image=None, color='0.85', hovercolor='0.95'):
        """
        Parameters
        ----------
        ax : matplotlib.axes.Axes
            The :class:`matplotlib.axes.Axes` instance the button
            will be placed into.

        label : str
            The button text. Accepts string.

        image : array, mpl image, Pillow Image
            The image to place in the button, if not *None*.
            Can be any legal arg to imshow (numpy array,
            matplotlib Image instance, or Pillow Image).

        color : color
            The color of the button when not activated

        hovercolor : color
            The color of the button when the mouse is over it
        """
        AxesWidget.__init__(self, ax)

        if image is not None:
            ax.imshow(image)
        self.label = ax.text(0.5,
                             0.5,
                             label,
                             verticalalignment='center',
                             horizontalalignment='center',
                             transform=ax.transAxes,
                             fontsize=13)

        self.cnt = 0
        self.observers = {}

        self.connect_event('button_press_event', self._click)
        self.connect_event('button_release_event', self._release)
        #self.connect_event('motion_notify_event', self._motion)
        ax.set_navigate(False)
        ax.set_facecolor(color)
        ax.set_xticks([])
        ax.set_yticks([])
        self.isIterating = False
        self.deleteFunc = None
        self.color = color
        self.hovercolor = hovercolor

        self._lastcolor = color
Ejemplo n.º 28
0
    def __init__(self, ax, name, label, valmin, valmax, valinit=0.5, width=1, valfmt='%1.2f',
                 time_index = None, closedmin=True, closedmax=True, slidermin=None,
                 slidermax=None, drag_enabled=True, **kwargs):
        """
        Create a slider from *valmin* to *valmax* in axes *ax*

        *valinit*
            The slider initial position

        *label*
            The slider label

        *valfmt*
            Used to format the slider value

        *closedmin* and *closedmax*
            Indicate whether the slider interval is closed

        *slidermin* and *slidermax*
            Used to constrain the value of this slider to the values
            of other sliders.

        additional kwargs are passed on to ``self.poly`` which is the
        :class:`matplotlib.patches.Rectangle` which draws the slider
        knob.  See the :class:`matplotlib.patches.Rectangle` documentation
        valid property names (e.g., *facecolor*, *edgecolor*, *alpha*, ...)
        """
        AxesWidget.__init__(self, ax)
        self.label = ax.text(-0.02, 0.5, label, transform=ax.transAxes,
                             verticalalignment='center',
                             horizontalalignment='right')
        self.valtext = None
        self.poly = None
        self.reinit(valmin, valmax, valinit, width, valfmt, time_index, **kwargs)

        self.name = name
        self.cnt = 0
        self.closedmin = closedmin
        self.closedmax = closedmax
        self.slidermin = slidermin
        self.slidermax = slidermax
        self.drag_active = False
        self.drag_enabled = drag_enabled
        self.observers = {}
        ax.set_yticks([])

        #ax.set_xticks([]) # disable ticks
        ax.set_navigate(False)
        self._connect()
Ejemplo n.º 29
0
    def __init__(self, ax, oncreated=None, lineprops=None):
        AxesWidget.__init__(self, ax)

        self.oncreated = oncreated
        self.verts = None

        if lineprops is None:
            lineprops = dict()
        self.line = pl.Line2D([], [], **lineprops)
        self.line.set_visible(False)
        self.ax.add_line(self.line)

        self.connect_event('button_press_event', self.onpress)
        # self.connect_event('button_release_event', self.onrelease)
        self.connect_event('motion_notify_event', self.onmove)
Ejemplo n.º 30
0
    def __init__(self, ax, oncreated=None, lineprops=None):
        AxesWidget.__init__(self, ax)

        self.oncreated = oncreated
        self.verts = None

        if lineprops is None:
            lineprops = dict()
        self.line = pl.Line2D([], [], **lineprops)
        self.line.set_visible(False)
        self.ax.add_line(self.line)

        self.connect_event('button_press_event', self.onpress)
        # self.connect_event('button_release_event', self.onrelease)
        self.connect_event('motion_notify_event', self.onmove)
Ejemplo n.º 31
0
    def __init__(self, coordinates, ax, callback_list=None):
        AxesWidget.__init__(self, ax)
        self.add_callback(callback_list)
        self.selected = False

        self.coordinates = tuple([c if c is not None else 0.5 for c in coordinates])  # Replaces all Nones with 0.5

        self.trackx = coordinates[0] is not None
        self.tracky = coordinates[1] is not None

        if not self.trackx and not self.tracky:
            raise Exception('Mode not supported')

        self.artist = None

        self.create_artist()
        self.connect_event('pick_event', lambda event: self.pick(event))
        self.connect_event('motion_notify_event', lambda event: self.motion_notify_event(event))
        # self.connect_event('button_press_event', lambda event : self.mouse_button_press(event))
        self.connect_event('button_release_event', lambda event: self.mouse_button_release(event))
Ejemplo n.º 32
0
    def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f',
                 closedmin=True, closedmax=True, slidermin=None,
                 slidermax=None, dragging=True, **kwargs):
        
        AxesWidget.__init__(self, ax)

        self.valmin = valmin
        self.valmax = valmax
        self.val = valinit
        self.valinit = valinit
        self.poly = ax.axhspan(valmin, valinit, 0, 1, **kwargs)

        self.hline = ax.axhline(valinit, 0, 1, color='r', lw=1)

        self.valfmt = valfmt
        ax.set_xticks([])
        ax.set_ylim((valmin, valmax))
        ax.set_yticks([])
        ax.set_navigate(False)

        self.connect_event('button_press_event', self._update)
        self.connect_event('button_release_event', self._update)
        if dragging:
            self.connect_event('motion_notify_event', self._update)
        self.label = ax.text(0.5, 1.03, label, transform=ax.transAxes,
                             verticalalignment='center',
                             horizontalalignment='center')

        self.valtext = ax.text(0.5, -0.03, valfmt % valinit,
                               transform=ax.transAxes,
                               verticalalignment='center',
                               horizontalalignment='center')

        self.cnt = 0
        self.observers = {}

        self.closedmin = closedmin
        self.closedmax = closedmax
        self.slidermin = slidermin
        self.slidermax = slidermax
        self.drag_active = False
Ejemplo n.º 33
0
    def __init__(self, ax, name, wdlength, min_wdlength):
        """
        Create a slider from *valmin* to *valmax* in axes *ax*

        """
        AxesWidget.__init__(self, ax)
        self.name = name
        self.wdlength = wdlength
        self.min_wdlength = min_wdlength
        self.voffset = 0
        self.connect()
        self.plotters = { }

        # 当前显示的范围。
        #self.xmax = len(data)
        #self.xmin = max(0, self.xmax-self.wdlength)
        #self.ymax = np.max(data.high[self.xmin : self.xmax].values) + self.voffset
        #self.ymin = np.min(data.low[self.xmin : self.xmax].values) - self.voffset

        self.cnt = 0
        self.observers = {}
Ejemplo n.º 34
0
    def __init__(self, ax, dx_frac=0.05, **rect_kw):
        self.rects = {}  # AxesWidget sets active=True, so rects needs to exist
        AxesWidget.__init__(self, ax)
        self.visible = True

        self.observers = {}
        self.cid = 0

        self.active_pick = None

        kw = dict(
            facecolor='gray',
            edgecolor='none',
            alpha=0.5,
            picker=5,
        )
        kw.update(rect_kw)
        self._make_rects(dx_frac, kw)

        self.connect_event('pick_event', self._pick),
        self.connect_event('button_release_event', self._release),
        self.connect_event('motion_notify_event', self._motion),
Ejemplo n.º 35
0
    def __init__(self, ax, callonangle=None, callonmove=None, **lineprops):
        """
        Add an AngleMeasurement widget to *ax*.

        *ax* : matplotlib.axes.Axes
        *lineprops* is a dictionary of line properties.
        """
        AxesWidget.__init__(self, ax)

        # Connect signals
        self.connect_event('button_press_event', self.on_press)
        self.connect_event('button_release_event', self.on_release)
        self.connect_event('motion_notify_event', self.on_motion)

        # Call functions
        self.callonangle = callonangle
        self.callonmove = callonmove

        # Variables
        self.visible = False
        self.angle = 0
        self.point1_xy = [0, 0]
        self.point2_xy = [0, 0]
        self.xLine = [0, 0]
        self.yLine = [0, 0]
        self.dx = 0
        self.dy = 0

        if lineprops:
            self.line = matplotlib.axes.Axes.plot(ax, self.xLine, self.yLine,
                                                  '', **lineprops)
        else:
            self.line = matplotlib.axes.Axes.plot(ax, self.xLine, self.yLine,
                                                  'r-')
            # line is a list of matplotlib.lines.Line2D
            self.line[0].set_linewidth(3)
        self.line[0].set_visible(self.visible)

        self.needclear = False
Ejemplo n.º 36
0
    def __init__(self,
                 ax,
                 horizOn=True,
                 vertOn=True,
                 useblit=False,
                 **lineprops):
        AxesWidget.__init__(self, ax)

        self.connect_event('motion_notify_event', self.onmove)
        self.connect_event('draw_event', self.clear)

        self.visible = True
        self.horizOn = horizOn
        self.vertOn = vertOn
        self.useblit = useblit and self.canvas.supports_blit

        if self.useblit:
            lineprops['animated'] = True
        self.lineh = ax.axhline(ax.get_ybound()[0], visible=False, **lineprops)
        self.linev = ax.axvline(ax.get_xbound()[0], visible=False, **lineprops)

        self.background = None
        self.needclear = False
Ejemplo n.º 37
0
    def __init__(self, ax, dx_frac=0.05, **rect_kw):
        self.rects = {}  # AxesWidget sets active=True, so rects needs to exist
        AxesWidget.__init__(self, ax)
        Actionable.__init__(self)
        self.visible = True

        self.observers = {}
        self.cid = 0

        self.active_pick = None

        kw = dict(
            facecolor='gray',
            edgecolor='none',
            alpha=0.5,
            picker=5,
        )
        kw.update(rect_kw)
        self._make_rects(dx_frac, kw)

        self.connect_event('pick_event', self._pick),
        self.connect_event('button_release_event', self._release),
        self.connect_event('motion_notify_event', self._motion),
Ejemplo n.º 38
0
    def __init__(self, ax, label, image=None, color="0.85", hovercolor="0.95"):
        AxesWidget.__init__(self, ax)

        if image is not None:
            ax.imshow(image)
        self.label = ax.text(
            0.5, 0.5, label, verticalalignment="center", horizontalalignment="center", transform=ax.transAxes
        )

        self.cnt = 0
        self.observers = {}

        self.connect_event("button_press_event", self._click)
        self.connect_event("button_release_event", self._release)
        self.connect_event("motion_notify_event", self._motion)
        ax.set_navigate(False)
        ax.set_axis_bgcolor(color)
        ax.set_xticks([])
        ax.set_yticks([])
        self.color = color
        self.hovercolor = hovercolor

        self._lastcolor = color
Ejemplo n.º 39
0
    def __init__(self, ax, s='', allowed_chars=None, type=str, **text_kwargs):
        AxesWidget.__init__(self, ax)
        self.ax.set_navigate(False)
        self.ax.set_yticks([])
        self.ax.set_xticks([])

        self.type = type
        self.allowed_chars = allowed_chars
        self.value = self.type(s)
        self.text = self.ax.text(0.025, 0.2, s,
                                 transform=self.ax.transAxes, **text_kwargs)

        self._cid = None
        self._cursor = None
        self._cursorpos = len(self.text.get_text())
        self.old_callbacks = {}

        self.cnt = 0
        self.observers = {}

        self.exit_cnt = 0
        self.exit_observers = {}

        self.connect_event('button_press_event', self._mouse_activate)
Ejemplo n.º 40
0
    def __init__(self,
                 ax,
                 label,
                 valmin,
                 valmax,
                 valinit=0.5,
                 valfmt='%1.2f',
                 closedmin=True,
                 closedmax=True,
                 slidermin=None,
                 slidermax=None,
                 dragging=True,
                 valstep=None,
                 **kwargs):
        """
        Parameters
        ----------
        ax : Axes
            The Axes to put the slider in.
        label : str
            Slider label.
        valmin : float
            The minimum value of the slider.
        valmax : float
            The maximum value of the slider.
        valinit : float, optional, default: 0.5
            The slider initial position.
        valfmt : str, optional, default: "%1.2f"
            Used to format the slider value, fprint format string.
        closedmin : bool, optional, default: True
            Indicate whether the slider interval is closed on the bottom.
        closedmax : bool, optional, default: True
            Indicate whether the slider interval is closed on the top.
        slidermin : Slider, optional, default: None
            Do not allow the current slider to have a value less than
            the value of the Slider `slidermin`.
        slidermax : Slider, optional, default: None
            Do not allow the current slider to have a value greater than
            the value of the Slider `slidermax`.
        dragging : bool, optional, default: True
            If True the slider can be dragged by the mouse.
        valstep : float, optional, default: None
            If given, the slider will snap to multiples of `valstep`.
        Notes
        -----
        Additional kwargs are passed on to ``self.poly`` which is the
        :class:`~matplotlib.patches.Rectangle` that draws the slider
        knob.  See the :class:`~matplotlib.patches.Rectangle` documentation for
        valid property names (e.g., `facecolor`, `edgecolor`, `alpha`).
        """
        AxesWidget.__init__(self, ax)

        if slidermin is not None and not hasattr(slidermin, 'val'):
            raise ValueError("Argument slidermin ({}) has no 'val'".format(
                type(slidermin)))
        if slidermax is not None and not hasattr(slidermax, 'val'):
            raise ValueError("Argument slidermax ({}) has no 'val'".format(
                type(slidermax)))
        self.closedmin = closedmin
        self.closedmax = closedmax
        self.slidermin = slidermin
        self.slidermax = slidermax
        self.drag_active = False
        self.valmin = valmin
        self.valmax = valmax
        self.valstep = valstep
        valinit = self._value_in_bounds(valinit)
        if valinit is None:
            valinit = valmin
        self.val = valinit
        self.valinit = valinit
        self.poly = ax.axvspan(valmin, valinit, 0, 1, **kwargs)
        self.vline = ax.axvline(valinit, 0, 1, color='r', lw=1)

        self.valfmt = valfmt
        ax.set_yticks([])
        ax.set_xlim((valmin, valmax))
        ax.set_xticks([])
        ax.set_navigate(False)

        self.connect_event('button_press_event', self._update)
        self.connect_event('button_release_event', self._update)
        if dragging:
            self.connect_event('motion_notify_event', self._update)
        self.label = ax.text(0.5,
                             -0.5,
                             label,
                             transform=ax.transAxes,
                             verticalalignment='center',
                             horizontalalignment='center')

        self.mintext = ax.text(-0.02,
                               0.5,
                               valfmt % valmin,
                               transform=ax.transAxes,
                               verticalalignment='center',
                               horizontalalignment='right')
        self.maxtext = ax.text(1.02,
                               0.5,
                               valfmt % valmax,
                               transform=ax.transAxes,
                               verticalalignment='center',
                               horizontalalignment='left')
        self.valtext = ax.text(0.5,
                               0.45,
                               valfmt % valinit,
                               transform=ax.transAxes,
                               verticalalignment='center',
                               horizontalalignment='center',
                               weight='bold')

        self.cnt = 0
        self.observers = {}

        self.set_val(valinit)
Ejemplo n.º 41
0
    def __init__(self,
                 ax,
                 label,
                 valmin,
                 valmax,
                 valinit=0.5,
                 valfmt='%1.2f',
                 closedmin=True,
                 closedmax=True,
                 slidermin=None,
                 slidermax=None,
                 dragging=True,
                 label_pos=(0.5, -0.005),
                 valtext_pos=(0.5, 1.005),
                 **kwargs):
        """
        Create a slider from *valmin* to *valmax* in axes *ax*.

        Additional kwargs are passed on to ``self.poly`` which is the
        :class:`matplotlib.patches.Rectangle` which draws the slider
        knob.  See the :class:`matplotlib.patches.Rectangle` documentation
        valid property names (e.g., *facecolor*, *edgecolor*, *alpha*, ...).

        Parameters
        ----------
        ax : Axes
            The Axes to put the slider in

        label : str
            Slider label

        valmin : float
            The minimum value of the slider

        valmax : float
            The maximum value of the slider

        valinit : float
            The slider initial position

        valfmt : str
            Used to format the slider value, fprint format string

        closedmin : bool
            Indicate whether the slider interval is closed on the bottom

        closedmax : bool
            Indicate whether the slider interval is closed on the top

        slidermin : Slider or None
            Do not allow the current slider to have a value less than
            `slidermin`

        slidermax : Slider or None
            Do not allow the current slider to have a value greater than
            `slidermax`


        dragging : bool
            if the slider can be dragged by the mouse

        """
        AxesWidget.__init__(self, ax)

        self.valmin = valmin
        self.valmax = valmax
        self.val = valinit
        self.valinit = valinit
        self.poly = ax.axhspan(valmin, valinit, 0, 1, **kwargs)

        self.hline = ax.axhline(valinit, 0, 1, color='r', lw=1)

        self.valfmt = valfmt
        ax.set_xticks([])
        ax.set_ylim((valmin, valmax))
        ax.set_yticks([])
        ax.set_navigate(False)

        self.connect_event('button_press_event', self._update)
        self.connect_event('button_release_event', self._update)
        if dragging:
            self.connect_event('motion_notify_event', self._update)
        self.label = ax.text(*label_pos,
                             label,
                             transform=ax.transAxes,
                             verticalalignment='top',
                             horizontalalignment='center',
                             rotation=90)

        self.valtext = ax.text(*valtext_pos,
                               valfmt % valinit,
                               transform=ax.transAxes,
                               verticalalignment='bottom',
                               horizontalalignment='center',
                               rotation=90)

        self.cnt = 0
        self.observers = {}

        self.closedmin = closedmin
        self.closedmax = closedmax
        self.slidermin = slidermin
        self.slidermax = slidermax
        self.drag_active = False
Ejemplo n.º 42
0
 def __init__(self, ax, orig_line, cropper, **opts):
     AxesWidget.__init__(self, ax)
     self.orig_line = orig_line
     self.cropper = cropper
     self.line, = ax.plot([], [], transform=self.ax.transAxes, **opts)
     self.orig_line.on_release(self.update)
Ejemplo n.º 43
0
    def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f',
                 closedmin=True, closedmax=True, slidermin=None, slidermax=None,
                 dragging=True, **kwargs):
        """
        Create a slider from *valmin* to *valmax* in axes *ax*

        *valinit*
            The slider initial position

        *label*
            The slider label

        *valfmt*
            Used to format the slider value

        *closedmin* and *closedmax*
            Indicate whether the slider interval is closed

        *slidermin* and *slidermax*
            Used to constrain the value of this slider to the values
            of other sliders.

        additional kwargs are passed on to ``self.poly`` which is the
        :class:`matplotlib.patches.Rectangle` which draws the slider
        knob.  See the :class:`matplotlib.patches.Rectangle` documentation
        valid property names (e.g., *facecolor*, *edgecolor*, *alpha*, ...)
        """
        AxesWidget.__init__(self, ax)

        self.valmin = valmin
        self.valmax = valmax
        self.val = valinit
        self.valinit = valinit
        self.poly = ax.axhspan(valmin,valinit,0,1, **kwargs)

        self.hline = ax.axhline(valinit,0,1, color='r', lw=1)


        self.valfmt=valfmt
        ax.set_yticks([])
        ax.set_ylim((valmin, valmax))
        ax.set_xticks([])
        ax.set_navigate(False)

        self.connect_event('button_press_event', self._update)
        self.connect_event('button_release_event', self._update)
        if dragging:
            self.connect_event('motion_notify_event', self._update)
        self.label = ax.text(0.5, 1.02, label, transform=ax.transAxes,
                             verticalalignment='bottom',
                             horizontalalignment='center')

        self.valtext = ax.text(0.5, -0.02, valfmt%valinit,
                               transform=ax.transAxes,
                               verticalalignment='top',
                               horizontalalignment='center')

        self.cnt = 0
        self.observers = {}

        self.closedmin = closedmin
        self.closedmax = closedmax
        self.slidermin = slidermin
        self.slidermax = slidermax
        self.drag_active  = False
Ejemplo n.º 44
0
    def __init__(self, ax, im):
        AxesWidget.__init__(self, ax)

        self.cbar = colorbar_factory(ax, im)
        self.fmt = self.cbar.formatter = OffsetFormatter()
        self.ax.yaxis.set_visible(True)
Ejemplo n.º 45
0
    def __init__(self, ax, s='', allowed_chars=None, type=str,
                 enter_callback=None, **text_kwargs):
        """
        Editable text box

        Creates a mouse-click callback such that clicking on the text box will
        activate the cursor.

        *WARNING* Activating a textbox will remove all other key-press
        bindings! They'll be stored in TextBox.old_callbacks and restored
        when TextBox.end_text_entry() is called.

        The default widget assumes only numerical data and will not
        allow text entry besides numerical characters and ('e','-','.')

        Parameters
        ----------
        *ax* : :class:`matplotlib.axes.Axes`
            The parent axes for the widget

        *s* : str
            The initial text of the TextBox.

        *allowed_chars* : seq
            TextBox will only respond if event.key in allowed_chars.  Defaults
            to None, which accepts anything.

        *type* : type
            Construct self.value using this type.  self.value is only updated
            if self.type(<text>) succeeds.

        *enter_callback* : function
            A function of one argument that will be called with
            TextBox.value passed in as the only argument when enter is
            pressed

        *text_kwargs* :
            Additional keywork arguments are passed on to self.ax.text()

        Call :meth:`on_onchanged` to connect to TextBox updates
        """
        AxesWidget.__init__(self, ax)
        self.ax.set_navigate(False)
        self.ax.set_yticks([])
        self.ax.set_xticks([])

        self.type = type
        self.allowed_chars = allowed_chars
        self.value = self.type(s)
        self.text = self.ax.text(0.025, 0.2, s,
                                 transform=self.ax.transAxes, **text_kwargs)

        self.enter_callback = enter_callback
        self._cid = None
        self._cursor = None
        self._cursorpos = len(self.text.get_text())
        self.old_callbacks = {}

        self.cnt = 0
        self.observers = {}

        self.connect_event('button_press_event', self._mouse_activate)
Ejemplo n.º 46
0
    def __init__(self,
                 ax,
                 label,
                 valmin,
                 valmax,
                 valinit=0.5,
                 valfmt='%1.2f',
                 closedmin=True,
                 closedmax=True,
                 slidermin=None,
                 slidermax=None,
                 dragging=True,
                 **kwargs):
        """
        Create a slider from *valmin* to *valmax* in axes *ax*

        *valinit*
            The slider initial position

        *label*
            The slider label

        *valfmt*
            Used to format the slider value

        *closedmin* and *closedmax*
            Indicate whether the slider interval is closed

        *slidermin* and *slidermax*
            Used to constrain the value of this slider to the values
            of other sliders.

        additional kwargs are passed on to ``self.poly`` which is the
        :class:`matplotlib.patches.Rectangle` which draws the slider
        knob.  See the :class:`matplotlib.patches.Rectangle` documentation
        valid property names (e.g., *facecolor*, *edgecolor*, *alpha*, ...)
        """
        AxesWidget.__init__(self, ax)

        self.valmin = valmin
        self.valmax = valmax
        self.val = valinit
        self.valinit = valinit
        self.poly = ax.axhspan(valmin, valinit, 0, 1, **kwargs)

        self.hline = ax.axhline(valinit, 0, 1, color='r', lw=1)

        self.valfmt = valfmt
        ax.set_yticks([])
        ax.set_ylim((valmin, valmax))
        ax.set_xticks([])
        ax.set_navigate(False)

        self.connect_event('button_press_event', self._update)
        self.connect_event('button_release_event', self._update)
        if dragging:
            self.connect_event('motion_notify_event', self._update)
        self.label = ax.text(0.5,
                             1.02,
                             label,
                             transform=ax.transAxes,
                             verticalalignment='bottom',
                             horizontalalignment='center')

        self.valtext = ax.text(0.5,
                               -0.02,
                               valfmt % valinit,
                               transform=ax.transAxes,
                               verticalalignment='top',
                               horizontalalignment='center')

        self.cnt = 0
        self.observers = {}

        self.closedmin = closedmin
        self.closedmax = closedmax
        self.slidermin = slidermin
        self.slidermax = slidermax
        self.drag_active = False