contour plots, heat plots, composed of several single plots

186 views
Skip to first unread message

felix...@googlemail.com

unread,
Sep 17, 2021, 3:59:42 PM9/17/21
to pyqtgraph
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


img_spec_part_plots.py

Patrick

unread,
Sep 20, 2021, 11:57:47 PM9/20/21
to pyqtgraph
Hi,

There is nothing fundamentally wrong with what you are doing. You can just keep creating ImageItems and adding them to the plot with appropriate scale and translate transforms applied. I have no idea how many you'd need to add before you run into performance issues. Obviously, with a very large data set you'd want to slice and/or downsample your data depending on the view range of the plot. If your spectral slices are small (a few data points) you may want to merge slices together (say 256--1024 pixels wide).

Here's some code which demonstrates the "new" way to do the translate and scale:

# ...
# plot = pyqtgraph plotitem

# Keep list of image items
spec_images = []

# Loop through existing data slices
# (or add each slice as they are acquired)
for specslice in specslices:
    # ...
    # t = time axis coordinates of slice
    # f = frequency axis of slice(s)
    # Compute scale factors for each image dimension
    # (if identical for each slice, could compute outside the loop instead)
    f_scale = (f[-1] - f[0])/(f.shape[0]-1) if f.shape[0] > 1 else 1.0
    t_scale = (t[-1] - t[0])/(t.shape[0]-1) if t.shape[0] > 1 else 1.0
    #...
    tr = QtGui.QTransform()
    # Centre pixels on the data points
    tr.translate(t[0] - t_scale/2, f[0] - f_scale/2)
    tr.scale(t_scale, f_scale)
    image = pg.ImageItem(specslice)
    image.setTransform(tr)
    plot.addItem(image)
    spec_images.append(image)


Patrick

felix...@googlemail.com

unread,
Sep 26, 2021, 6:40:55 AM9/26/21
to pyqtgraph
Dear Patrick,

thanks for your nice answer and pointing me to the new way to do transformations and scaling!

Kind regards
feli_x
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages