我正在尝试创建两个可自动调整大小的图表,使用PyQt5 / PySide2 QSplitter小部件。但是,当我缩小图表时,它们的标题和x轴标签会重叠,如下所示。看起来很糟糕。有人知道更好的方法来解决这个问题吗?
以下是我的示例代码
import numpy as np
from PySide2 import QtWidgets, QtCore
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
import matplotlib
matplotlib.use('Qt5Agg')
class MyChart(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
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)
splitter.addWidget(canvas1)
splitter.addWidget(canvas2)
self.setCentralWidget(splitter)
self.show()
if __name__ == '__main__':
app = QtWidgets.QApplication([])
w = MyChart()
app.exec_()