Dear all,

because matplotlib.pyplot is slow, I want to use pyqtgraph to display plots 
of scalar-valued functions of two variables. The figures I want to achieve 
are similar to contour plots or heat plots, in general they are false color 
displays of scalar-valued functions of two variables. In my special case 
they are parts of spectrogram data, which are combined to the plot of a 
whole spectrogram.

My question is, if there is already a function or an object in pyqtgraph 
available, which is suitable to combine these parts of the spectrogram to a 
large spectrogram and show the result as an image? The axes should be 
suitably configurable and the position and the scale of the little 
spectrogram parts should also be choosable.

I found a way to combine my little spectrogram parts using a 
GraphicsLayoutWidget, 
an ImageItem and translate and scale methods of the ImageItem object. This 
works fine besides the "DeprecationWarning: Deprecated Qt API, will be 
removed in 0.13.0.", which is shown because of the usage of the translate 
and scale methods.

I wonder if there exists already another more simple way inside pqtgraph to 
show individual spectrogram parts as a whole spectrogram?

An example is attached to the e-mail, which shows the principle of my 
ideas. There are shown individual images of sin-functions in y-direction 
and x-direction instead of spectrogram data to make the example easy.

Do you have suggestions?
feli_x


-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/6851b96f-e6af-4c1d-a9b5-09ae3e8e7c30n%40googlegroups.com.
# simulate contour plots, heat plots
# in other words: a false color plot of a scalar-valued functions of two variables

import numpy as np
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
from matplotlib import cm
pg.setConfigOption('background', 'w')  # globally set background to white ...
pg.setConfigOption('foreground', 'k')  # ... and foreground to black
app = pg.mkQApp("Image View")
win = pg.GraphicsLayoutWidget()
win.resize(800,800)
win.show()
p = win.addPlot()

# set background to blue color
img_backgr = pg.ImageItem()
p.addItem(img_backgr)
data_backgr = np.zeros((2,2))
img_backgr.setImage(data_backgr)
img_backgr.scale(400/2,200/2)
# define 0th image
img_0 = pg.ImageItem()
p.addItem(img_0)
y = np.arange(0,200,1)*6*np.pi/200
data_0 = np.zeros([100,200])
for i in range(100):
    for j in range(200):
        data_0[i,j] = np.sin(y[j])
img_0.setImage(data_0)
img_0.translate(0,0)  # first translate then scale
img_0.scale(100/np.shape(data_0)[0],200/np.shape(data_0)[1])
# define 1st image
img_1 = pg.ImageItem()
p.addItem(img_1)
x = np.arange(0,200,1)*6*np.pi/200
data_1 = np.zeros([200,100])
for i in range(200):
    for j in range(100):
        data_1[i,j] = np.sin(x[i])
img_1.setImage(data_1)
img_1.translate(200,100)  # first translate then scale
img_1.scale(200/np.shape(data_1)[0],100/np.shape(data_1)[1])
# set axes
p.setLabel('bottom', "x axis", units='1')
p.setLabel('left', "y axis", units='1')
# set color map
cmap = pg.colormap.get(cm.jet,source="matplotlib")  # use cm.jet from matplotlib
lut = cmap.getLookupTable(0.0,1.0,512)  # equally-spaced lookup table of RGB(A) values created by interpolation
img_backgr.setLookupTable(lut)
img_0.setLookupTable(lut)
img_1.setLookupTable(lut)

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore,'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

Reply via email to