1
我有matplotlib
嵌入在PyQt4
應用程序,我正在處理。問題是當我動態地向圖中添加一個子圖時,數字會隨着每個添加的子圖一起壓縮。我認爲我可以通過將該數字設置爲QScrollArea
來解決此問題,但這不起作用(據我所知)。這裏是什麼,我想會的工作QScrollWidget中的PyQt4 + matplotlib
import os
os.environ['QT_API'] = 'pyside'
from PySide.QtGui import *
from PySide.QtCore import *
import matplotlib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
class Canvas(FigureCanvasQTAgg):
def __init__(self, parent=None):
self.figure = Figure()
super(Canvas, self).__init__(self.figure)
ax = self.figure.add_subplot(1,1,1)
ax.plot([1,2,3])
self.draw()
def add_subplot(self, data=[]):
rows = len(self.figure.axes) + 1
for index, axes in enumerate(self.figure.axes, start=1):
axes.change_geometry(rows, 1, index)
ax = self.figure.add_subplot(rows, 1, index+1)
ax.plot(data)
self.draw()
class Main(QWidget):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.canvas = QScrollArea(self)
self.canvas.setWidget(Canvas(self))
self.canvas.setWidgetResizable(True)
for x in range(5):
self.canvas.widget().add_subplot()
layout = QVBoxLayout(self)
layout.addWidget(self.canvas)
app = QApplication([])
main = Main()
main.show()
app.exec_()
通知所有的圖表是如何一起搗爛在同一個可視空間,然後顯示一個例子嗎?我不必滾動查看其他圖表。我不確定如何完全做到這一點。
任何人都知道如何做到這一點或以另一種方式做到這一點?