作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 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/
我是一名优秀的程序员,十分优秀!