Thanks for the help. Both ways worked exactly how I needed them to, but I 
also want to be able to set a sinusoidal and logarithmic transformation on 
the axes. Is this possible without using a matrix?

On Tuesday, July 12, 2022 at 10:17:47 PM UTC-7 [email protected] wrote:

> In addition to what Patrick said; you can also call setRect on the image, 
> to place it where you want
>
> image.setRect(pg.Qt.QtCore.QRectF(x0, y0, width, height))
>
> Keep in mind that x0 and y0 represent the top-left corner of the rectangle.
>
> On Tue, Jul 12, 2022 at 7:17 PM Patrick <[email protected]> wrote:
>
>> Hi Alan,
>>
>> The new, accepted way to do this is by applying a QTransform to the 
>> ImageItem. Something like this:
>>
>> # Axis labels or limits for the x and y pixels
>> # If pixel values, they need to be uniform intervals
>> x = np.array([-1024, 1024])
>> y = np.array([-1024, 1024])
>>
>> # Scale in units per pixel
>> x_scale = (x[-1] - x[0])/(x.shape[0]-1) if x.shape[0] > 1 else 1.0
>> y_scale = (y[-1] - y[0])/(y.shape[0]-1) if y.shape[0] > 1 else 1.0
>>
>> # Create QTransform and apply to ImageItem
>> # Adjust so values are centred on pixels
>> tr = QtGui.QTransform()
>> tr.translate(x[0] - x_scale/2, y[0] - y_scale/2)
>> tr.scale(x_scale, y_scale)
>> image.setTransform(tr)
>>
>> It's just calculating the translation and pixel scale required to map the 
>> pixel coordinates to the desired axis coordinates.
>>
>> Patrick
>>
>>
>>
>>
>>
>> On Wednesday, 13 July 2022 at 7:56:44 am UTC+9:30 Alan Wang wrote:
>>
>>> Hi all,
>>> I'm making a graph that displays an image with an ImageItem and 
>>> GraphicsLayoutWidget, but I'd like to label the image with axes on a 
>>> different system of coordinates. When I create a graph, the axes go from 0 
>>> to 4096 (the size of the image), but I'd like the axes to be labeled from 
>>> -1024 to 1024, essentially remapping the coordinates to a different scale. 
>>> Is there a way to do this? 
>>>
>>> Thank you
>>>
>> -- 
>> 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/85ab2e7c-5418-4946-9110-800983b05387n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/pyqtgraph/85ab2e7c-5418-4946-9110-800983b05387n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/e8bda188-65f0-4d42-9658-e2da78cdbd3en%40googlegroups.com.

Reply via email to