JuliaImages / ImageView.jl

Interactive display of images and movies
MIT License
135 stars 34 forks source link

ImageView doesn't display data if plotting with PyPlot occurs first #295

Closed mgalenb closed 6 months ago

mgalenb commented 9 months ago

I am getting a strange error when using ImageView and PyPlot in the same project. This is on a Linux machine with Julia 1.9.3 and most recent versions of ImageView (0.12.0) and PyPlot (2.11.2)

I made a clean project with activate --temp and add ImageView,PyPlot

Then I do this, ordering seems to mater?

using PyPlot
fig,ax=subplots()
ax.plot(rand(100))
#displays a plot with data

using ImageView
ImageView.imshow(rand(100,100,10))
#displays a window but no data inside, see picture

Screenshot 2023-10-28 at 11 17 20 AM

It appears related to plotting with PyPlot first

if I do this

using ImageView,PyPlot
ImageView.imshow(rand(100,100,10))
#good image

Screenshot 2023-10-28 at 11 21 20 AM

I can even make plots with PyPlot and also keep making new windows with ImageView.imshow, but I have to do ImageView.imshow first.

jwahlstrand commented 9 months ago

I can confirm this, also on Linux. It seems like it must be some sort of bad interaction between the Tk and GTK event loops. There is a lot of information on this in #262, #149, #128, and https://github.com/JuliaGraphics/Gtk.jl/issues/493. It sounds like changing the PyPlot backend was settled on as the solution.

On ImageView 0.11.7, if you use PyPlot first and then call imshow, the image window does show up and can be interacted with, but the PyPlot window refuses to close and the REPL becomes unresponsive. Like 0.12.0, calling imshow before PyPlot functions seems to work fine.

jwahlstrand commented 6 months ago

This is an issue with Gtk4, not this package, so I'm going to close this. I added a note to the Gtk4 README about PyPlot issues and workarounds.