How to hide axis on plot when GraphicsLayoutWidget is used

3,002 views
Skip to first unread message

olivie...@gmail.com

unread,
Jan 9, 2016, 4:12:29 AM1/9/16
to pyqtgraph
Hi,

How to hide an axis when "GraphicsLayoutWidget" is used?
The folowing code doesn't work.

Thanks

PS: HistogramLUTItem works only for gray images. No version for RGB images ?


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from pyqtgraph.Qt import QtGui
from PIL import Image
import pyqtgraph as pg
import numpy as np


class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.win = pg.GraphicsLayoutWidget()
        self.setCentralWidget(self.win)
#        pg.dbg()
       
    def displayIma(self):
        _in_data = Image.open('../../IMAGES/kitten.jpg')
        self.img = np.asarray(_in_data, dtype=np.uint8).transpose([1,0,2])
       
        self.imv = pg.ImageItem()
        self.imv.setImage(self.img, autoHistogramRange=True, autoLevels=True, autoDownsample=True)
        self.img_view_box = self.win.addViewBox(invertY=True)
        self.img_view_box.setBackgroundColor([80, 80, 100])
        self.img_view_box.setAspectLocked()
        self.img_view_box.addItem(self.imv)

        # Only for gray images, not RGB :-( !!!
#        self.hist = pg.HistogramLUTItem()
#        self.hist.setImageItem(self.imv)
#        self.win.addItem(self.hist)
       
        # Histo for RGB images
        customXaxis = pg.AxisItem(orientation='left', showValues=False)
        customXaxis.showLabel(False)
        self.PlotHisto = self.win.addPlot(row=1, col=0, axisItems={'left': customXaxis})
        self.PlotHisto.setMouseEnabled(False, False)
        self.PlotHisto.autoRange()
        self.PlotHisto.enableAutoRange()
        #self.PlotHisto.setXRange(0, 256, padding=0)
        self.PlotHisto.setRange(xRange=(0,255), padding=0)
        self.PlotHisto.setLimits(yMin=0)

        _color = ('r','g','b')
        _brush = ((255,0,0,70), (0,255,0,70), (0,0,255,70))
        for channel,col in enumerate(_color):
            histr = np.histogram(self.img[..., channel], bins=255)
            self.PlotHisto.plot(histr[0], pen=col, fillLevel=-0.3, brush=_brush[channel])

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    win = MainWindow()
    win.displayIma()
    win.resize(800, 600)
    win.show()

    sys.exit(app.exec_())



vas...@gmail.com

unread,
Jan 9, 2016, 5:19:23 AM1/9/16
to pyqt...@googlegroups.com
self.PlotHisto.hideAxis('bottom')
self.PlotHisto.hideAxis('left')

--
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/8c97e2b6-57db-43bd-b76d-f970a1e9a226%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

olivie...@gmail.com

unread,
Jan 9, 2016, 6:30:16 AM1/9/16
to pyqtgraph
Thanks, but it doesn't work.
I want only hidden the ticks and the associated values.
The second axis appeared with my  "solution" is always there (see caption).



        # Histo for RGB images
        customXaxis = pg.AxisItem(orientation='left', showValues=False)
        customXaxis.showLabel(False)
        self.PlotHisto = self.win.addPlot(row=1, col=0, axisItems={'left': customXaxis})
        self.PlotHisto.setMouseEnabled(False, False)
        self.PlotHisto.autoRange()
        self.PlotHisto.enableAutoRange()
        #self.PlotHisto.setXRange(0, 256, padding=0)
        self.PlotHisto.setRange(xRange=(0,255), padding=0)
        self.PlotHisto.setLimits(yMin=0)
        self.PlotHisto.removeItem(customXaxis)
        self.PlotHisto.hideAxis('left')




Le samedi 9 janvier 2016 11:19:23 UTC+1, Vasilije VaskeVanja a écrit :
self.PlotHisto.hideAxis('bottom')
self.PlotHisto.hideAxis('left')


vas...@gmail.com

unread,
Jan 9, 2016, 8:01:43 AM1/9/16
to pyqt...@googlegroups.com
I guess that you need somehow to update your pyqtgraph installation:
http://stackoverflow.com/questions/33717000/pyqtgraph-custom-tick-labels-potential-bug

--
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.

olivie...@gmail.com

unread,
Jan 9, 2016, 8:20:20 AM1/9/16
to pyqtgraph
Good ! Thanks.
Reply all
Reply to author
Forward
0 new messages