0

I am working on a GUI on python 3.5, the point is that I show an image on the canvas and want to use the matplotlib tools to zoom on an image using the zoom to rectangle or pan/zoom buttons, then the area that has been zoomed store it on a variable to do some image processing, I can implement a button to extract an area using ginput() but I lose from view the original image. Now I wanna try using the tools of matplotlib.

How can I do it? Thanks

EDIT: This is how I am coding it:

#On _init_ function on class I declare the figure like this
def __init__(self):
    self.raiz = tk.Tk()
    self.raiz.title("SOFTWARE KI-67")
    self.raiz.geometry('1000x800')

    self.figura=plt.figure()

    self.canvas = FigureCanvasTkAgg(self.figura, self.cuadro_plot)
    self.canvas.get_tk_widget().pack(side=tk.TOP, expand=tk.TRUE, fill=tk.BOTH)
    self.canvas.draw()
    self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.cuadro_plot)
    self.canvas._tkcanvas.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)


#This is the cutting function
def recortar(self):
    if self.brecortar.config('relief')[-1] == 'sunken':
        self.brecortar["state"] = 'normal'
    else:
        self.brecortar.config(relief="sunken")
        self.brecortar["state"] = 'disabled'
        pts = np.asarray(plt.ginput(2, show_clicks=True))
        pts = np.sort(pts, axis=0)
        pts = (np.floor(pts))
        print(pts)

        minX = int(min(pts[0][0], pts[1][0]))
        maxX = int(max(pts[0][0], pts[1][0]))
        minY = int(min(pts[0][1], pts[1][1]))
        maxY = int(max(pts[0][1], pts[1][1]))

        print(minX, maxX, minY, maxY)
        img2 = self.img.copy()
        img2 = img2[minY:maxY, minX:maxX]

        self.img = img2
        self.plotear(img2)

        self.brecortar.config(relief="raised")
        self.brecortar["state"] = 'normal'

I read the comment of Ernest, but how could I implement the

ax.callbacks.connect('xlim_changed', on_xlims_change)
ax.callbacks.connect('ylim_changed', on_ylims_change)

??

Ivan
  • 1,069
  • 1
  • 9
  • 14

0 Answers0