'Text moves axes upon panning with constrained layout

If I pan the function in the following example, the axis position is moved in order to keep TEXT in the canvas. Is there a way to keep the axes and to treat TEXT just like the plotted line while keeping constrained_layout=true?

Screenshot1 Screenshot2

import tkinter as tk
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.backends.backend_tkagg as tkagg


class NewGUI():
    def __init__(self):

        self.root = tk.Tk()
        self.root.geometry('500x400+200+200')
        self.plot_frame = tk.Frame()
        self.plot_frame.place(x=10, y=10, relheight=0.7, relwidth=0.7, anchor='nw')
        self.plot_window = Plotwindow(self, (18,12))
        self.root.mainloop()

        
class Plotwindow():
    def __init__(self, root, size):
        fig = mpl.figure.Figure(size, constrained_layout=True)
        ax = fig.add_subplot(111)
        canvas = tkagg.FigureCanvasTkAgg(fig, master=root.plot_frame)
        canvas.get_tk_widget().pack()
        toolbar = tkagg.NavigationToolbar2Tk(canvas, root.root)
        toolbar.update()
        
        x = np.arange(0, 5, 0.1)
        y = np.sin(x)
        ax.plot(x, y)
        ax.text(0, 0, 'TEXT')


if __name__ == '__main__':
    new = NewGUI()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source