コード例 #1
0
 def record(self, event):
     if event.inaxes is None:
         return
     self.slit = Slit(self.axes, self.pixel_scale)
     self.slits.append(self.slit)
     self.cursor = widgets.Cursor(self.axes, useblit=False, color='red', linewidth=1)
     self.cid = self.fig.canvas.mpl_connect('button_press_event', self.get_click)
コード例 #2
0
def onpress(event):
    global y1, cursor, lines
    y1 = event.ydata
    clear_lines()
    add_line(y1)
    print('press event')
    cursor = widgets.Cursor(ax, vertOn=False, color='black', linestyle='--')
コード例 #3
0
    def _initLayout(self):
        """Initializes the figure layout.
        """

        grid = gridspec.GridSpec(3,
                                 3,
                                 self._figure,
                                 width_ratios=[0.3, 4, 1],
                                 height_ratios=[1, 4, 0.3],
                                 wspace=0.3)

        self._mainAxes = plt.subplot(grid[1, 1])
        self._mainAxes.set_xlim([0, self._dataset.shape[1]])
        self._mainAxes.set_ylim([0, self._dataset.shape[0]])
        if self._standAlone:
            self._cursor = widgets.Cursor(self._mainAxes, useblit=True)

        self._cbarAxes = plt.subplot(grid[1, 0])
        self._rowSliceAxes = plt.subplot(grid[0, 1])
        self._rowSliceAxes.xaxis.set_tick_params(bottom=False,
                                                 labelbottom=False,
                                                 top=True,
                                                 labeltop=True)
        self._colSliceAxes = plt.subplot(grid[1, 2])
        self._colSliceAxes.tick_params(axis="x", rotation=270)
        self._colSliceAxes.yaxis.set_tick_params(bottom=False,
                                                 labelbottom=False,
                                                 top=True,
                                                 labeltop=True)

        self._image = None

        self._selectedPixel = (0, 0)
コード例 #4
0
def interactiveValueSelector(ax, x_value=True, y_value=True):
    
    """Allows to choose values from the axes of a plot.
    
    Parameters
    ----------
    ax : plt.Axes
        The axes instance of the plot from where you want to choose.
    x_value=True : bool
        Whether to return the x value.
    y_value=True : bool
        Whether to return the y value.
    
    Returns
    -------
    value : float
        If only one value is required. This is the x value if 'x_value=True' 
        and 'y_value=False'. Otherwise, it is the y value.
    values : tuple
        If both values are required. Then it returns (x value, y value).
    
    See also
    --------
    plt.Axes
    wid.Cursor
    """
    
    ax.autoscale(False)
    cursor = wid.Cursor(ax, useblit=True, 
                        linestyle='--', color='red', linewidth=2)
    if not y_value:
        cursor.horizOn = False
    if not x_value:
        cursor.vertOn = False
    plt.show()
    
    values = plt.ginput()[0]
    if x_value:
        plt.vlines(values[0], ax.get_ylim()[0], ax.get_ylim()[1], 
                   linestyle='--', linewidth=2, color='red')
    if y_value:
        plt.hlines(values[1], ax.get_xlim()[0], ax.get_xlim()[1], 
                   linestyle='--', linewidth=2, color='red')
    cursor.visible = False
    cursor.active = False

    if x_value and y_value:
        return values
    elif x_value:
        return values[0]
    else:
        return values[1]
コード例 #5
0
    def __init__(self, img):
        #figWH = (8,5) # in
        self.fig = plt.figure()  #figsize=figWH)
        self.ax = self.fig.add_subplot(111)
        self.img = img
        self.ax.matshow(img.T, interpolation='nearest', origin='lower')
        self.xindex = 0
        self.yindex = 0

        self.cursor = mwidgets.Cursor(self.ax, useblit=True, color='k')
        #self.cursor.horizOn = False

        self.connect = self.ax.figure.canvas.mpl_connect
        self.disconnect = self.ax.figure.canvas.mpl_disconnect

        self.clickCid = self.connect("button_press_event", self.onClick)
コード例 #6
0
    def __init__(self, x, y):
        #figWH = (8,5) # in
        self.fig = plt.figure()  #figsize=figWH)
        self.ax = self.fig.add_subplot(111)
        self.x = x
        self.y = y
        self.ax.plot(x, y)
        self.indices = []
        self.lines = []  # will contain 2D line objects for each of 4 lines

        self.cursor = mwidgets.Cursor(self.ax, useblit=True, color='k')
        self.cursor.horizOn = False

        self.connect = self.ax.figure.canvas.mpl_connect
        self.disconnect = self.ax.figure.canvas.mpl_disconnect

        self.clickCid = self.connect("button_press_event", self.onClick)
コード例 #7
0
    def __init__(self, img):
        #figWH = (8,5) # in
        self.fig = plt.figure()  #figsize=figWH)
        self.ax = self.fig.add_subplot(111)
        self.img = img
        #plt.imshow(img)
        self.ax.imshow(img, cmap="gray")
        self.x = []
        self.y = []

        self.cursor = mwidgets.Cursor(self.ax,
                                      useblit=True,
                                      color='Red',
                                      linewidth=0.5)
        #self.cursor.horizOn = False

        self.connect = self.ax.figure.canvas.mpl_connect
        self.disconnect = self.ax.figure.canvas.mpl_disconnect

        self.clickCid = self.connect("button_press_event", self.onClick)
コード例 #8
0
ファイル: gameGui.py プロジェクト: yogeshg/small-projects
    def paint(self):
        if (self.ax):
            self.ax.clear()
        if (self.fig):
            self.fig.clf()
        plt.close()
        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(1, 1, 1)

        self.imgplot = self.ax.imshow(self.game.board.tolist(),
                                      interpolation='none')

        self.cursor = mwidgets.Cursor(self.ax, useblit=True, color='k')
        self.cursor.horizOn = False

        self.connect = self.ax.figure.canvas.mpl_connect
        self.disconnect = self.ax.figure.canvas.mpl_disconnect

        self.clickCid = self.connect("button_press_event", self.onClick)

        plt.show()
コード例 #9
0
        range_bins = int(float(sys.argv[3]))
        res_range = float(sys.argv[4])

        comp_lin = float(sys.argv[5])
        comp_log = 20 * np.log10(comp_lin)

        log_lin = float(sys.argv[6])
        range_bias = float(sys.argv[7])

        # ---

        fig = plt.figure(figsize=(6, 6))
        ax = plt.subplot(1, 1, 1)  # rows, cols, idx

        cursor = wgt.Cursor(ax, useblit=True, color='white', linewidth=1)

        fig.canvas.set_window_title('...')

        ax.set_title('Doppler-Range FFT Heatmap [{};{}]'.format(
            range_bins, doppler_bins),
                     fontsize=10)
        ax.set_xlabel('Longitudinal distance [m]')
        ax.set_ylabel('Radial velocity [m/s]')

        ax.grid(color='white', linestyle=':', linewidth=0.5)

        move_figure(fig, (0 + 45 * 4, 0 + 45 * 4))

        scale = max(doppler_bins, range_bins)
        ratio = range_bins / doppler_bins
コード例 #10
0
ファイル: iplots.py プロジェクト: TsSales/Masters_code
def model_masses(area1, area2, background=None):
    """ Function to plant 2D point masses by clicking with the mouse. 
    Inputs: 
    * area1 = [xmin, xmax, zmin, zmax] : list with 2D Cartesian coordinate ranges(x,z).
    * area2 = [rhomin, rhomax, rhomin, rhomax] : list with density-constrast and depth ranges.

           
    Output : x,z,rho = lists with the picked values from the mouse clicking. The size is related to the number of clicks
    OBS: PAY ATTENTION TO THE NUMBER OF CLICKS IN BOTH PLOT AREAS. OTHERWISE THE REMAINING CODE WILL NOT WORK! 
    """

    # ------------ auxiliar functios to perform the clicking--------------------------:
    def draw_guide1(px, py):
        if len(x) != 0 or len(y) != 0:
            tmpline1.set_data([x[-1], px], [y[-1], py])

    # --------------------------------------------------------------------------------:
    def draw_guide2(px, py):
        if len(rho) != 0 or len(z) != 0:
            tmpline2.set_data([rho[-1], px], [z[-1], py])

    # --------------------------------------------------------------------------------:
    def move(event):
        if event.inaxes != ax1 or event.inaxes != ax2:
            return 'plot area wrongly set up. Please, check.'
        if event.inaxes == ax1:
            if picking[0]:
                draw_guide1(event.xdata, event.ydata)
                ax1.figure.canvas.draw()
        elif event.inaxes == ax2:
            if picking[0]:
                draw_guide2(event.xdata, event.ydata)
                ax2.figure.canvas.draw()

    # --------------------------------------------------------------------------------:
    def click(event):
        if event.inaxes == ax1:
            # count for click instances:
            if event.button == 1:
                click1.append(1.0)
                #---- append list with picked values -----:
                x.append(event.xdata)
                y.append(event.ydata)
                plotx.append(event.xdata)
                ploty.append(event.ydata)

            #-------------- plot data -------------------:
            line1.set_color('k')
            line1.set_marker('o')
            line1.set_linestyle('None')
            line1.set_data(plotx, ploty)
            # -------- display the number of clicks in the subtitle --------:
            ax1.set_title('Number of clicks =' + str(len(click1)),
                          fontsize=12,
                          color='black')

            ax1.figure.canvas.draw()

        elif event.inaxes == ax2:
            # count for click instances:
            if event.button == 1:
                click2.append(1.0)

            #---- append list with picked values:
            rho.append(event.xdata)
            z.append(event.ydata)
            plotrho.append(event.xdata)
            plotz.append(event.ydata)

            #-------------- plot data -------------------:
            line2.set_color('b')
            line2.set_marker('*')
            line2.set_linestyle('None')
            line2.set_data(plotrho, plotz)
            # -------- display the number of clicks in the subtitle --------:
            ax2.set_title('Number of clicks =' + str(len(click2)),
                          fontsize=12,
                          color='blue')
            ax2.figure.canvas.draw()

# --------------------------------------------------------------------------------:

    def erase(event):
        if event.inaxes == ax1:
            if event.key == 'e' and picking[0]:
                # count for click instances:
                click1.pop()
                #---- remove list with "unpicked" values:
                x.pop()
                y.pop()
                plotx.pop()
                ploty.pop()

            #-------------- plot data -------------------:
            line1.set_data(plotx, ploty)
            line1.set_linestyle('None')
            draw_guide1(event.xdata, event.ydata)
            # -------- display the number of clicks in the subtitle --------:
            ax1.set_title('Number of clicks =' + str(len(click1)),
                          fontsize=12,
                          color='black')
            ax1.figure.canvas.draw()

        elif event.inaxes == ax2:
            if event.key == 'e' and picking[0]:
                # count for click instances:
                click2.pop()
                # s2 = str(click2)
                rho.pop()
                z.pop()
                plotrho.pop()
                plotz.pop()
                #-------------- plot data -------------------:
                line2.set_data(plotrho, plotz)
                line2.set_linestyle('None')
                draw_guide2(event.xdata, event.ydata)
                # -------- display the number of clicks in the subtitle --------:
                ax2.set_title('Number of clicks =' + str(len(click2)),
                              fontsize=12,
                              color='blue')
                ax2.figure.canvas.draw()

    #---------------------------------------------------------------------------------:

    fig1, (ax1, ax2) = pyplot.subplots(1, 2)

    fig1.suptitle(
        'Click for (x, z) coordinates and (rho, rho) values.'
        'Press keybord < e > to erase undesired values. Close figure when done',
        fontsize=16)
    ax1.set_xlim(area1[0], area1[1])
    ax1.set_ylim(area1[2], area1[3])
    ax1.grid()
    ax1.set_xlabel(' Horizontal coordinate x(m)')
    ax1.set_ylabel(' Depth (m)')
    ax1.invert_yaxis()

    # check for optional input:
    if background != None:
        xv = background[0]
        zv = background[1]
        ax1.plot(xv, zv, '-k')

    ax2.set_xlim(area2[0], area2[1])
    ax2.set_ylim(area2[2], area2[3])
    ax2.grid()

    # --------- change the position of the tick label--------------:
    ax2.yaxis.tick_right()

    # --------- invert axis for depth positive down --------------:
    ax2.set_xlabel('density')
    ax2.set_ylabel('density')

    # --------- cursor use for better visualization ------------- :
    cursor1 = widgets.Cursor(ax1, useblit=True, color='black', linewidth=2)
    cursor2 = widgets.Cursor(ax2, useblit=True, color='blue', linewidth=2)

    # ----- for the case of new clicks -------:
    x = []
    y = []
    z = []

    plotx = []
    ploty = []

    rho = []
    plotz = []
    plotrho = []
    click1 = []
    click2 = []
    # ----------------- cleaning line object for plotting ------------------:
    line1, = ax1.plot([], [])
    tmpline1, = ax1.plot([], [])
    line2, = ax2.plot([], [])
    tmpline2, = ax2.plot([], [])

    # ------------ Hack because Python 2 doesn't like nonlocal variables that change value -------:
    # Lists it doesn't mind.
    picking = [True]
    fig1.canvas.mpl_connect('button_press_event', click)
    fig1.canvas.mpl_connect('key_press_event', erase)
    fig1.canvas.mpl_connect('motion_notify_event', move)
    pyplot.show()
    return x, y, rho
コード例 #11
0
 def cursor(self, i_c):
     self.curs_l.append(
         wdg.Cursor(self.axs[i_c], useblit=True, color='red', linewidth=1))
コード例 #12
0
for line in input.readlines():
    data.append(map(float, line.split("\t")))

input.close()

data = numpy.array(data)

print data[1, :]

figure = pyplot.figure()
axis = figure.add_subplot(111)
axis.plot(data[:, 0], data[:, 1], label=names[1])
axis.plot(data[:, 0], data[:, 2], label=names[2])
axis.plot(data[:, 0], data[:, 3], label=names[3])

cursor = widgets.Cursor(axis, useblit=True, color="black")
cursor.vertOn = False


def onClick(event):
    count_data = data[data[:, 0] > data[-1, 0] - 5000, :]
    print data
    print count_data, len(count_data)

    threshold = cursor.lineh.get_ydata()[0]
    count = 0
    for i in xrange(len(count_data) - 1):
        if count_data[i, 1] <= threshold and count_data[i + 1, 1] > threshold:
            count += 1
    print count / 5, count