Arben John Avillanosa
Arben John Avillanosa

Reputation: 213

How to change the starting axes of Image to pyqtgraph?

I want to add the Image to specific axes point in the graph Instead of starting to 0,0. I want it to start to specific y-axis. For example, I want the image to be set to 0,50

Here is my code

import pyqtgraph as pg
import numpy as np

ctl_graph = pg.GraphicsLayoutWidget()
spectrogram_plot = ctl_graph.addPlot(row=8, col=0, colspan=2)
histogram_spectrogram = pg.HistogramLUTItem()
histogram_spectrogram.gradient.loadPreset("flame")
spectrogram_img = pg.ImageItem()
random_number_lists = []
random_numbers_1 = np.random.normal(0, 1, 100)
random_numbers_2 = np.random.normal(0, 1, 100)
random_numbers_3 = np.random.normal(0, 1, 100)
random_number_lists.append(random_numbers_1)
random_number_lists.append(random_numbers_2)
random_number_lists.append(random_numbers_3)

spectrogram_img.setImage(random_number_lists.T, autoLevels=False, autoRange=False)
spectrogram_plot.addItem(spectrogram_img)
histogram_spectrogram.setImageItem(spectrogram_img)

# Setting of graph limits
spectrogram_plot.setLimits(xMin=0, xMax=100, yMin=50, yMax=100)
spectrogram_img.scale(np.amax(random_numbers_1)/ random_numbers_1.size, np.amax(random_numbers_2)/random_numbers_2.size)

The resulting image graph is not what i want. What i want is to start the plotting of image to 0,50 not in 0,0

Upvotes: 0

Views: 1395

Answers (1)

knalj
knalj

Reputation: 1504

As shown in this example: https://github.com/pyqtgraph/pyqtgraph/blob/develop/examples/imageAnalysis.py#L73

spectrogram_img.translate(x0, y0)

should do the trick

Upvotes: 1

Related Questions