Problem between Matplotlib figure & PyQt5/PySide2 QSplitter Widget

I am trying to create 2 plot figures that can be auto-resized with the PyQt5/PySide2 QSplitter Widget. However, when I shrink the plots, their title and x-axis labels get overlapped, as shown below. It looks broken. Does anyone know better tricks to solve this problem?

Here is my sample code

import numpy as np
from PySide2 import QtWidgets, QtCore
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
import matplotlib

class MyChart(QtWidgets.QMainWindow):
    def __init__(self):

        canvas1 = FigureCanvasQTAgg(Figure(figsize=(20,12))) 
        ax1 = canvas1.figure.add_subplot(111)
        ax1.plot(np.sin(np.linspace(0, 4, 1000)))
        ax1.set_title('Chart 1')

        canvas2 = FigureCanvasQTAgg(Figure(figsize=(20,12))) 
        ax2 = canvas2.figure.add_subplot(111)
        ax2.plot(np.sin(5 * np.linspace(0, 4, 1000)))
        ax2.set_title('Chart 2')
        splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)

if __name__ == '__main__':
    app = QtWidgets.QApplication([])
    w = MyChart()

Use constrained_layout?

hi @jklymak, I have tried your suggestion and it works!! Thank you very much!!

Great - If you find any real bad hiccups, let us know. Though of course be aware that if you make the figure too small constrained_layout won’t help’