I need to display an image volume with multiple slices, similar to sliceViewer in Matlab. However, the current imshow function only supports RBG(A) or 2D scalar data.
Proposed solution
The code example here shows how to display multiple slice images, but there is a lot of code to write, which is not convenient. Maybe one solution is to provide a wrap function (i.e. imshow_3d or slice_viewer) that implements the example code somehow?
I just tried to write a wrap function for the example code here, but the scroll wheel doesn't work. The reason is beyond my knowledge. Does anyone know why?
Does the example work if you just run the example code as is? (Just to work out if it is an OS/backend issue or not. For reference it works for me on CentOS 7 with QtAgg.)
Does the example work if you just run the example code as is? (Just to work out if it is an OS/backend issue or not. For reference it works for me on CentOS 7 with QtAgg.)
Thanks for your reply. I figured that I have to return and receive the variable tracker to make the scroll wheel work. I guess this is related to the life cycle of variable tracker? An example code is below:
This is not an elegant solution though, because I have to return the variable tracker. In addition, the y label is occupied by slice index. An ideal solution is something like sliceViewer in Matlab, which has a slider to allow changing slices.
The example exists primarily to illustrate event handling. It is intentional minimal and not designed as a fully-fledged image viewer.
In scope:
we should describe that the user has to keep a reference to the tracker so that it lives for the whole lifetime of the figure.
Out of scope:
Matplotlib provides the basic building blocks for plotting. We won't provide a native image slice viewer ourselves. This should be done by a third party package building on top of matplotlib.
Matplotlib provides the basic building blocks for plotting. We won't provide a native image slice viewer ourselves. This should be done by a third party package building on top of matplotlib.
I guess this is related to the life cycle of variable tracker? An example code is below:
Yes, we only hold onto weak refs to the objects when the callbacks get registered so when the object get garbage collected the callbacks go away and hence no interaction. (There has been some discussion of changing that so our callbacks hold hard references but that is well outside of scope here).
In addition to (as time suggests) making it clear in this example you need to keep the tracker alive, it might be worth adding a linked slider from matplotlib.widgets?
I wonder if the title of the example should be changed? If you search image slicing in Python on Google, you get this page which is not very good for the stated purpose and not the actual point of the example.
Activity
ustcfdm commented on Nov 4, 2022
I just tried to write a wrap function for the example code here, but the scroll wheel doesn't work. The reason is beyond my knowledge. Does anyone know why?
oscargus commented on Nov 4, 2022
Does the example work if you just run the example code as is? (Just to work out if it is an OS/backend issue or not. For reference it works for me on CentOS 7 with QtAgg.)
ustcfdm commented on Nov 4, 2022
Thanks for your reply. I figured that I have to return and receive the variable tracker to make the scroll wheel work. I guess this is related to the life cycle of variable tracker? An example code is below:
This is not an elegant solution though, because I have to return the variable tracker. In addition, the y label is occupied by slice index. An ideal solution is something like sliceViewer in Matlab, which has a slider to allow changing slices.
timhoffm commented on Nov 4, 2022
The example exists primarily to illustrate event handling. It is intentional minimal and not designed as a fully-fledged image viewer.
In scope:
Out of scope:
ksunden commented on Nov 4, 2022
Also, if your primary goal is a nice, interactive, viewer for multidimensional image data, you may be interested in https://napari.org
story645 commented on Nov 4, 2022
Depending on the domain, maybe xarray or mne/nipy related packages might also fit the bill.
tacaswell commented on Nov 4, 2022
Yes, we only hold onto weak refs to the objects when the callbacks get registered so when the object get garbage collected the callbacks go away and hence no interaction. (There has been some discussion of changing that so our callbacks hold hard references but that is well outside of scope here).
In addition to (as time suggests) making it clear in this example you need to keep the tracker alive, it might be worth adding a linked slider from matplotlib.widgets?
tacaswell commented on Nov 4, 2022
Tasks:
Adding the slider is medium because it will require linking some callbacks and convincing everyone it is a good idea ;)
timhoffm commented on Nov 4, 2022
I'm -0.5 on adding a slider. This makes the example much more complex and is outside the scope of the event-handing topic.
jklymak commented on Nov 4, 2022
I wonder if the title of the example should be changed? If you search image slicing in Python on Google, you get this page which is not very good for the stated purpose and not the actual point of the example.
timhoffm commented on Nov 4, 2022
I don't get Matplotlib on the first page of google results 🤷♂️
Anyway, changing the title is a good idea -> done in #24366
For simplicity, I've kept the filename.