Help with Adjusting axes of PlotItem object

70 views
Skip to first unread message

Andrew More

unread,
Sep 6, 2024, 1:05:23 PM9/6/24
to pyqtgraph
I'd like to find a way to manually change the displayed values on the axes of a PlotItem without changing any aspect of how the data in the PlotItem is displayed. As far as I can tell, changing anything about the axes necessitates also shifting the values of the data so it displays properly, but I'd like to avoid this. Is there a way to do this?

Martin Chase

unread,
Sep 10, 2024, 3:03:48 PM9/10/24
to pyqt...@googlegroups.com
Hey Andrew,

I'm sorry, I'm unable to determine what you mean by "changing anything about the axes". Could you post sample code demonstrating what you're trying to do?

Best,
 - Martin

On Fri, Sep 6, 2024 at 10:05 AM Andrew More <andrew....@gmail.com> wrote:
I'd like to find a way to manually change the displayed values on the axes of a PlotItem without changing any aspect of how the data in the PlotItem is displayed. As far as I can tell, changing anything about the axes necessitates also shifting the values of the data so it displays properly, but I'd like to avoid this. Is there a way to do this?

--
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 pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/a75051e6-d0ee-448b-a73f-d1e51b417c7an%40googlegroups.com.

Andrew More

unread,
Sep 16, 2024, 10:16:03 AM9/16/24
to pyqtgraph
I am trying to determine a way to alter the numbers displayed on ticks of the axes of an ImageView object showing a PlotItem. However, I'd only like this change to be shown visually on the axis ticks and not change the shape, scope, or underlying calculations of the plotted data. As far as I can tell, manually accessing the axis objects with:
```python
plot = pg.PlotItem()
# Initialize ImageView with the custom PlotItem
view = pg.ImageView(view=plot)

# Access the x-axis (bottom axis) of the PlotItem
x_axis = plot.getAxis('bottom')

# Define custom tick positions and labels
ticks = [(50, '50'), (100, '100'), (150, '150'), (200, '200'), (250, '250')]

# Apply the custom ticks to the x-axis
x_axis.setTicks([ticks])
```
Would alter the X Axis ticks as desired, but would also manipulate data displayed in the underlying plot as it seems to take into account the axis object when displaying data.
Basically I would like to know if there's a way to create a visual change in the displayed axes without changing the underlying axis used to find the shape of the plot. Since the data I am trying to display will shift dynamically, I'd like to be able to change these axis ticks dynamically as well as follows:
```python
import PyQt6
import pyqtgraph as pg
import numpy as np

#Initializing plot item and image view structure
plot = pg.PlotItem()
view = pg.ImageView(view=plot)
view.imageItem.setImage(np.ones((2048,2048), dtype=np.uint8) * 255,autoRange=False)

#Depending on user interaction that image content will be changed
if (event_happens):
    view.imageItem.setImage(new_image_content, autoRange=False)
    ## Here I would like I way to change the displayed numbers on the axes of the ImageView object without affecting the displayed data
```
Please let me know if I need to offer further clarification of my question. Thank you
Reply all
Reply to author
Forward
0 new messages