gpt4 book ai didi

pyqt - 每次绘制时,Matplotlib 嵌入式 PyQt4 图形都会调整大小

转载 作者:行者123 更新时间:2023-12-01 00:39:16 32 4
gpt4 key购买 nike

我在 PyQt4 应用程序中有一个嵌入式 matplotlib 图。这是我根据 http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.html 上的 Qt4 嵌入示例制作的绘图小部件。 .不幸的是,每次我添加一个新图时,这个图都会稍微缩小。我有两个在 QGridLayout 中并排对齐的绘图小部件,如果这会有所不同的话。

这种奇怪行为的原因是什么?

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure

class MultiPlot(FigureCanvas):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
FigureCanvas.__init__(self, fig)
self.setParent(parent)
self.setMinimumSize(300, 200)
self.setMaximumSize(600, 400)

def plot(self,x,y):
print "Plot"
self.axes.plot(x,y)
FigureCanvas.updateGeometry(self)

def changePlot(self,plotNum,x,y):
print "Change plot",plotNum
self.axes.lines[plotNum].set_data(x,y)
FigureCanvas.updateGeometry(self)

最佳答案

我在小部件上使用 setFixedSize 解决了这个问题,而不是让布局管理器调整大小。我不明白为什么布局管理器想要在添加更多绘图时缩小小部件,但问题还是解决了

关于pyqt - 每次绘制时,Matplotlib 嵌入式 PyQt4 图形都会调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8485850/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com