Discussion:
[pyqtgraph] how to remove border of graphicsLayoutWidget
j***@polytechnique.edu
2018-12-06 15:08:34 UTC
Permalink
Hi
I use a graphicsLayoutWidget to plot an image from a camera. But i want to
remove the 2 black border around and to full fill the widget.
Does somebody know how to do it?

My program is :

self.winImage = pg.GraphicsLayoutWidget(border=(100,100,1))
self.winImage.setAspectLocked(True)
self.winImage.setContentsMargins(1,1,1,1)
vbox2=QVBoxLayout()
vbox2.addWidget(self.winImage)
vbox2.setContentsMargins(0,0,0,0)
self.p1=self.winImage.addPlot()
self.imh=pg.ImageItem(border='w')
self.p1.addItem(self.imh)
self.p1.setMouseEnabled(x=False,y=False)
self.p1.setContentsMargins(1,1,1,1)
self.p1.setAspectLocked(True,ratio=1)
self.p1.setContentsMargins(0,0,0,0)

hMainLayout=QHBoxLayout()
hMainLayout.addLayout(vbox2)
hMainLayout.addLayout(vbox1)
hMainLayout.setContentsMargins(0,0,0,0)
hMainLayout.setStretch(2,1)

self.setLayout(hMainLayout)
self.setContentsMargins(1,1,1,1)
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/b59f331a-5db3-4d1c-983f-3c666212ec57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Patrick
2018-12-07 03:04:00 UTC
Permalink
Hi,

There's two sets of "borders" I think you're talking about. Outside the
yellow box and inside.
For outside, this is the contents margin of the GraphicsLayout -- but
you'll need to get the reference to that from the central item in the
GraphicsLayoutWidget:

self.winImage.ci.setContentsMargins(0, 0, 0, 0)

For inside the yellow box, this is about the extent of the ViewBox
(essentially the plot limits). Set them manually eg:

self.p1.setLimits(xMin=0, 100, yMin=0, yMax=100)

So an example would be:

#!/usr/bin/env python3

import numpy as np
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QVBoxLayout, QHBoxLayout
import pyqtgraph as pg

class TestImage(QtWidgets.QMainWindow):

def __init__(self):
super().__init__()

# Create empty data structure
self.data = np.random.rand(100, 100)

self.winImage = pg.GraphicsLayoutWidget()
self.winImage.ci.setContentsMargins(0, 0, 0, 0)
self.p1 = self.winImage.addPlot()
self.imh = pg.ImageItem(self.data)
self.p1.addItem(self.imh)
self.p1.setMouseEnabled(x=False,y=False)

self.p1.hideAxis('left')
self.p1.hideAxis('bottom')
self.p1.hideButtons()

self.p1.scale(1.0, 1.0)
self.p1.setLimits(xMin=0, xMax=self.data.shape[0], yMin=0, yMax=self
.data.shape[1])

self.setCentralWidget(self.winImage)

def main():
import sys
app = QtWidgets.QApplication(sys.argv)
mainwindow = TestImage()
mainwindow.show()
sys.exit(app.exec_())

if __name__ == '__main__':
main()


Patrick
Post by j***@polytechnique.edu
Hi
I use a graphicsLayoutWidget to plot an image from a camera. But i want
to remove the 2 black border around and to full fill the widget.
Does somebody know how to do it?
self.winImage = pg.GraphicsLayoutWidget(border=(100,100,1))
self.winImage.setAspectLocked(True)
self.winImage.setContentsMargins(1,1,1,1)
vbox2=QVBoxLayout()
vbox2.addWidget(self.winImage)
vbox2.setContentsMargins(0,0,0,0)
self.p1=self.winImage.addPlot()
self.imh=pg.ImageItem(border='w')
self.p1.addItem(self.imh)
self.p1.setMouseEnabled(x=False,y=False)
self.p1.setContentsMargins(1,1,1,1)
self.p1.setAspectLocked(True,ratio=1)
self.p1.setContentsMargins(0,0,0,0)
hMainLayout=QHBoxLayout()
hMainLayout.addLayout(vbox2)
hMainLayout.addLayout(vbox1)
hMainLayout.setContentsMargins(0,0,0,0)
hMainLayout.setStretch(2,1)
self.setLayout(hMainLayout)
self.setContentsMargins(1,1,1,1)
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/f9ab55ce-5d4a-49e6-b1e1-3ae6073a1543%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
j***@polytechnique.edu
2018-12-07 09:05:37 UTC
Permalink
Hi
It 's perfect
Thanks a lot
Post by j***@polytechnique.edu
Hi
I use a graphicsLayoutWidget to plot an image from a camera. But i want
to remove the 2 black border around and to full fill the widget.
Does somebody know how to do it?
self.winImage = pg.GraphicsLayoutWidget(border=(100,100,1))
self.winImage.setAspectLocked(True)
self.winImage.setContentsMargins(1,1,1,1)
vbox2=QVBoxLayout()
vbox2.addWidget(self.winImage)
vbox2.setContentsMargins(0,0,0,0)
self.p1=self.winImage.addPlot()
self.imh=pg.ImageItem(border='w')
self.p1.addItem(self.imh)
self.p1.setMouseEnabled(x=False,y=False)
self.p1.setContentsMargins(1,1,1,1)
self.p1.setAspectLocked(True,ratio=1)
self.p1.setContentsMargins(0,0,0,0)
hMainLayout=QHBoxLayout()
hMainLayout.addLayout(vbox2)
hMainLayout.addLayout(vbox1)
hMainLayout.setContentsMargins(0,0,0,0)
hMainLayout.setStretch(2,1)
self.setLayout(hMainLayout)
self.setContentsMargins(1,1,1,1)
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/14e4b799-e9fa-4092-88d3-dedfc36f264a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...