pyqt figure大小
时间: 2023-10-25 13:14:38 浏览: 99
你可以使用 PyQt 中的 FigureCanvasQTAgg 作为 Matplotlib 图形的嵌入式画布。要设置 Figure 的大小,你可以在创建 Figure 对象时传入 figsize 参数。例如,以下代码创建了一个大小为 6x4 英寸的 Figure:
```python
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# Create a Figure object with figsize=(6, 4)
fig = Figure(figsize=(6, 4))
# Add a subplot to the Figure
ax = fig.add_subplot(111)
# Plot some data on the Axes
ax.plot([1, 2, 3], [4, 5, 6])
# Create a canvas for the Figure
canvas = FigureCanvas(fig)
# Set the canvas as the central widget of the main window
self.setCentralWidget(canvas)
# Create a PyQt application instance
app = QApplication(sys.argv)
# Create the main window
main_window = MainWindow()
# Show the main window
main_window.show()
# Run the event loop
sys.exit(app.exec_())
```
你可以根据自己的需要调整 figsize 的大小。
阅读全文