Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 发出「;“动态”;matplotlib中的填充_Python_Python 2.7_Matplotlib_Pyqt_Pyqt4 - Fatal编程技术网

Python 发出「;“动态”;matplotlib中的填充

Python 发出「;“动态”;matplotlib中的填充,python,python-2.7,matplotlib,pyqt,pyqt4,Python,Python 2.7,Matplotlib,Pyqt,Pyqt4,我一直在尝试在matplotlib图形上设置固定大小的填充(以像素为单位)。我从来没有找到一个适合我在internet上的需要的解决方案,因此我不得不对此进行一些变通,这是通过以下代码完成的: def resizeEvent(self,e): windowWidth=self.geometry().width() windowHeight=self.geometry().height() #print(windowWidth,windowHeight) figur

我一直在尝试在matplotlib图形上设置固定大小的填充(以像素为单位)。我从来没有找到一个适合我在internet上的需要的解决方案,因此我不得不对此进行一些变通,这是通过以下代码完成的:

def resizeEvent(self,e):
    windowWidth=self.geometry().width()
    windowHeight=self.geometry().height()
    #print(windowWidth,windowHeight)
    figure.subplots_adjust(left=100.0/windowWidth,right=1-100.0/windowWidth, top=1-100.0/windowHeight,bottom=100.0/windowHeight)
手动调整窗口大小时效果很好(我们每边都有100px的填充)

不幸的是,当单击“最大化”时,即使打印返回正确的窗口大小(1920像素),填充(0到1)似乎等于它以前的值。 第二次单击“还原向下”会将填充设置为最大化时应该具有的值

我真的不明白这里发生了什么,我一定错过了什么。。。 如果您需要更多信息,如更多代码,请告诉我


感谢您的帮助:)

我过去也遇到过类似的问题(图形在启动时没有调整大小),并将图形子绘图的重新计算移到了
绘图方法。类似这样的东西(我使用紧凑的布局,但你明白了):


是的,在这种情况下确实需要重新绘制。但是,由于我有许多绘图的图形,draw()有点慢,所以我让应用程序仅在maximize和restore上重新绘制:)。
class PlotWidget(FigureCanvas):

    def __init__(self):
        self.__resizing_needed = True

    def draw(self):
        if self.__resizing_needed:
            self.__resizing_needed = False
            try:
                self.figure.tight_layout()
            except ValueError:
                # Set the minimumSize of this widget to prevent this
                print('Plot too small.')

        super(PlotWidget, self).draw()

    def resizeEvent(self, event):
        self.__resizing_needed = True
        super(PlotWidget, self).resizeEvent(event)