I have been working on a realtime spectrogram and I have it working for the most part. I followed this tutorial, which got me this far.
But I would like go get rid of the histogram, and add basically matlabs equivalent of the colorbar. Preferably above the spectrogram but below the power graphs. This is my setup plot code.
pg.setConfigOptions(imageAxisOrder='row-major')
pg.mkQApp()
win = pg.GraphicsLayoutWidget()
# restrict size of plot areas
win.ci.layout.setColumnMaximumWidth(1, 100)
win.ci.layout.setRowMaximumHeight(1, 200)
p2=win.addPlot(row=1,col=0,rowspan=1,colspan=1)
p1=win.addPlot(row=2,col=0,rowspan=3,colspan=1)
img = pg.ImageItem()
spec_hist = pg.PlotItem()
xscale = 1.0/((data_window.shape[1]/fs))
yscale = (1./fs)*packet_send*samples_per_packet
img.scale(xscale, yscale)
img.rotate(270)
p1.addItem(img)
win.nextRow()
win.nextRow()
win.nextRow()
hist=pg.HistogramLUTItem()
hist.setImageItem(img)
win.addItem(hist)
win.show()
hist.gradient.restoreState({'mode': 'rgb','ticks': [(0.5, (0, 182, 188, 255)),(1.0, (246, 111, 0, 255)),(0.0, (75, 0, 113, 255))]})
img.setImage(data_window, clear=True,levels=[-10, 180])
img.translate(0,fc/xscale)
p2.addLegend()
p2.showGrid(x= True, y = True)
c1=p2.plot(freq,spec_window,pen='r',name='Max over time')
c2=p2.plot(freq,data_window[0,:],pen='b',name='Instantaneous')
p1.setLabel('bottom', "Frequency", units='Hz')
p1.setLabel('left', "Time", units='s')
p2.setLabel('bottom', "Frequency", units='Hz')
p2.setLabel('left', "Power", units='dBFS')
I got that removing the 3x nextRows() and commenting win.addItem(hist) gets rid of the histogram(from view anyway), and deleting everything relating to the histogram completely removes the histogram but also changes my image to black and white. How should I go about this?
I had the same problem. After a while a ran into this: https://pypi.org/project/pyqtgraph-extensions/
Within that package there is matlab like colorbar that worked best for me.