def background_image(self, file):
        """Set the file image as background image"""
        if self.bg_img:
            self.bg_img.remove()

        datafile = get_sample_data(file)
        img = plt.imread(datafile)
        im = OffsetImage(img)
        im.set_zoom(min(1. * self.canvas.window.get_size()[0] / len(im.properties()['data'][0]),
                        1. * self.canvas.window.get_size()[1] / len(im.properties()['data'])))
        self.bg_img = AnnotationBbox(im, (0.5, 0.5), xycoords='data', frameon=False)
        self.bg_img.set_zorder(-1)
        plt.gca().add_artist(self.bg_img)
        self.do_refresh()
Example #2
0
    def background_image(self, file):
        """Set the file image as background image"""
        if self.bg_img:
            self.bg_img.remove()

        datafile = get_sample_data(file)
        img = plt.imread(datafile)
        im = OffsetImage(img)
        im.set_zoom(
            min(
                1. * self.canvas.window.get_size()[0] /
                len(im.properties()['data'][0]),
                1. * self.canvas.window.get_size()[1] /
                len(im.properties()['data'])))
        self.bg_img = AnnotationBbox(im, (0.5, 0.5),
                                     xycoords='data',
                                     frameon=False)
        self.bg_img.set_zorder(-1)
        plt.gca().add_artist(self.bg_img)
        self.do_refresh()