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_())