Python matplotlib.pyplot.connect() Examples

The following are code examples for showing how to use matplotlib.pyplot.connect(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: PDS_Compute_MTF   Author: bvnayak   File: PDS_Compute_MTF.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, filename):
        self.filename = filename
        self.image_data = cv2.imread(filename, 0)
        fig_image, current_ax = plt.subplots()
        plt.imshow(self.image_data, cmap='gray')
        eh = EventHandler(self.filename)
        rectangle_selector = RectangleSelector(current_ax,
                                               eh.line_select_callback,
                                               drawtype='box',
                                               useblit=True,
                                               button=[1, 2, 3],
                                               minspanx=5, minspany=5,
                                               spancoords='pixels',
                                               interactive=True)
        plt.connect('key_press_event', eh.event_exit_manager)
        plt.show() 
Example 2
Project: 3d-vehicle-tracking   Author: ucbdrive   File: show_labels.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def show(self):
        # Read and draw image
        dpi = 80
        w = 16
        h = 9
        self.fig = plt.figure(figsize=(w, h), dpi=dpi)
        self.ax = self.fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=False)
        if len(self.image_paths) > 1:
            plt.connect('key_release_event', self.next_image)
        self.show_image()
        plt.show() 
Example 3
Project: 3d-vehicle-tracking   Author: ucbdrive   File: show_labels.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def show(self):
        # Read and draw image
        dpi = 80
        w = self.image_width / dpi  # 16
        h = self.image_height / dpi  # 9
        self.fig = plt.figure(figsize=(w, h), dpi=dpi)
        self.ax = self.fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=False)
        # if len(self.image_paths) > 1:
        plt.connect('key_release_event', self.next_image)
        self.show_image()
        plt.show() 
Example 4
Project: exit-signs   Author: daniel-j-h   File: label-image.py    MIT License 5 votes vote down vote up
def main():
    args = mkArguments()

    image = io.imread(args.image)

    plt.imshow(image)

    points = []

    def onButton(event):
        x, y = int(event.xdata), int(event.ydata)
        points.append((x, y))
        print('Rectangle[{}]: at {},{}'.format('start' if len(points) % 2 != 0 else 'end', x, y))

    def onKey(event):
        if event.key == 'q' and points:
            points.pop()
        elif event.key == 'w':
            exit('Error: discarding rectangles, label again')
        elif event.key == 'e':
            plt.close()

    plt.connect('button_press_event', onButton)
    plt.connect('key_press_event', onKey)

    plt.title('mouse press: add point, q: pop point, w: discard, e: next')
    plt.axis('off')
    plt.show()

    if not points or len(points) % 2 != 0:
        exit('Error: unable to make up rectangles from no or odd number of points')

    with open(args.labelFile, 'a') as handle:
        writer = CSVWriter(handle)
        for i in range(0, len(points) - 1, 2):
            p0, p1 = points[i], points[i+1]
            (x0, y0) = np.min([p0, p1], axis=0)
            (x1, y1) = np.max([p0, p1], axis=0)

            # Region is made up of: path, x0, y0, x1, y1 (bottom left, top right)
            writer.writerow([abspath(args.image), x0, y0, x1, y1]) 
Example 5
Project: bdd-data   Author: ucbdrive   File: show_labels.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def show(self):
        # Read and draw image
        dpi = 80
        w = 16
        h = 9
        self.fig = plt.figure(figsize=(w, h), dpi=dpi)
        self.ax = self.fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=False)
        if len(self.image_paths) > 1:
            plt.connect('key_release_event', self.next_image)
        self.show_image()
        plt.show() 
Example 6
Project: bdd-data   Author: ucbdrive   File: show_labels.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def show(self):
        # Read and draw image
        dpi = 80
        w = 16
        h = 9
        self.fig = plt.figure(figsize=(w, h), dpi=dpi)
        self.ax = self.fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=False)
        # if len(self.image_paths) > 1:
        plt.connect('key_release_event', self.next_image)
        self.show_image()
        plt.show() 
Example 7
Project: gprMax   Author: gprMax   File: convert_png2h5.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, im, materials):
        """
        Args:
            im (ndarray): Pixels of the image.
            materials (list): To store selected RGB(A) values of selected pixels.
        """
        self.im = im
        self.materials = materials
        plt.connect('button_press_event', self) 
Example 8
Project: YOLOv3-Counter-Strike-Global-Offensive   Author: sainimohit23   File: create_annotationsV2.py    MIT License 5 votes vote down vote up
def line_select_callback(clk, rls):
    global tl_list
    global br_list
    global object_list
    global class_list
    plt.connect('key_press_event', set_class)
    tl_list.append((int(clk.xdata), int(clk.ydata)))
    br_list.append((int(rls.xdata), int(rls.ydata)))
    class_list.append(clas)
    if clas == '0':
        object_list.append(obj[0])
    else:
        object_list.append(obj[1]) 
Example 9
Project: Synthetic-video-generation-for-Autonomous-cars   Author: anubhav0fnu   File: show_labels.py    GNU General Public License v3.0 5 votes vote down vote up
def show(self):
        # Read and draw image
        dpi = 80
        w = 16
        h = 9
        self.fig = plt.figure(figsize=(w, h), dpi=dpi)
        self.ax = self.fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=False)
        if len(self.image_paths) > 1:
            plt.connect('key_release_event', self.next_image)
        self.show_image()
        plt.show() 
Example 10
Project: Synthetic-video-generation-for-Autonomous-cars   Author: anubhav0fnu   File: show_labels.py    GNU General Public License v3.0 5 votes vote down vote up
def show(self):
        # Read and draw image
        dpi = 80
        w = 16
        h = 9
        self.fig = plt.figure(figsize=(w, h), dpi=dpi)
        self.ax = self.fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=False)
        # if len(self.image_paths) > 1:
        plt.connect('key_release_event', self.next_image)
        self.show_image()
        plt.show() 
Example 11
Project: BitMEX-Open-Interest-chart   Author: Effanuel   File: main.py    MIT License 4 votes vote down vote up
def run_program() -> None:
    """
    This class initialization calls inherited constructor OrderManager
    which calls chart function
    """
    try:
        if len(sys.argv) == 2:
            try:
                # Read data into x,y,z arrays
                readData(sys.argv[1])
                if (
                    settings.ENABLE_HORIZONTAL_LINES_ON_HOVER
                    or settings.ENABLE_VERTICAL_LINES_ON_HOVER
                ):
                    print("hello")
                    # Enable onHoverEffect
                    plt.connect("motion_notify_event", onMouseEvent)

                # INIT PRICE CHART
                ax1[0].plot(x, y, color=price_color, linewidth=1)
                ax1[0].set_ylabel("Price", color=price_color)
                ax1[0].set_xlim(xmin=-5, xmax=x[-1] + 25)  # no empty space on left side
                # INIT OPEN-INTEREST CHART
                ax1[1].plot(x, z, color=interest_color, linewidth=1)
                ax1[1].set_xlabel("Ticks (1 tick = 5s)", color=interest_color)
                ax1[1].set_ylabel("Open Interest", color=interest_color)
                ax1[1].set_xlim(
                    xmin=-5, xmax=x[-1] + 25
                )  # no empty space on left/right side

                plt.tight_layout()
                plt.show()
            except (OSError, IOError) as e:
                print("Wrong file name.")
            except KeyError as e:
                print("Wrong file format.")

        else:
            chart = Chart()  # Is alive while the chart window is opened
            if settings.EXPORT_DATA_TO_FILE_AFTER_CHART_CLOSE is True:
                chart.export_data_to_csv("data.csv")  # Export data to csv file
            else:
                sys.exit()  # Closes the program if chart window is closed
    except (KeyboardInterrupt, SystemExit):
        sys.exit() 
Example 12
Project: PerceptionAndSlam_KTHFSDV1718   Author: javirrs   File: cone_img_processing2.py    GNU Affero General Public License v3.0 4 votes vote down vote up
def main(mode):
    desired_img_number = 0
    image_count = 0  
    cwd = os.getcwd()
    image_folder = './test_videos/cone_samples/'
    if mode is 0:
        for image_file in (os.listdir(image_folder)):
            img = image_file
            fig, ax = plt.subplots(1)
            image = cv2.imread(image_folder + image_file)
            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            ax.imshow(image)    
            #frame = cv2.imread(os.path.join(folder,image_file))

            output = detectCone1(image)

            if output == 0:
                print("Yellow Cone")
            elif output == 1:
                print('Blue Cone')
            elif output == 2:
                print('Orange Cone')
            else:
                print('!!!NO CONE!!!')

            key = plt.connect('key_press_event', onkeypress)
            plt.show()

            # cv2.imshow('original image', frame)
            # cv2.waitKey(0)
    elif mode is 1:
        #img = image_file
        fig, ax = plt.subplots(1)
        image = cv2.imread(image_folder + '114.jpg')
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        ax.imshow(image)    
        #frame = cv2.imread(os.path.join(folder,image_file))

        output = detectCone1(image)

        if output == 0:
            print("Yellow Cone")
        elif output == 1:
            print('Blue Cone')
        elif output == 2:
            print('Orange Cone')
        else:
            print('!!!NO CONE!!!')

        key = plt.connect('key_press_event', onkeypress)
        plt.show()