JuliaPy / PyPlot.jl

Plotting for Julia based on matplotlib.pyplot
https://github.com/JuliaPy/PyPlot.jl
MIT License
478 stars 88 forks source link

Cannot open multiple figures #316

Closed tpdsantos closed 6 years ago

tpdsantos commented 7 years ago

Since the last update from PyPlot, PyCall and Conda, everytime I use this function :

function PlotData(BalanceTime,Balance,AbsorbanceTime,Absorbance,Wavelength)
  Balfig = figure("Mass") ;
  Absfig = figure("Absorbance") ;
  if length(Balance) > 1
    plot(BalanceTime,Balance,figure=Balfig)
    title("Mass vs time")
    xlabel("time (s)")
    ylabel("Mass (g)")
  else
    close(Balfig)
  end
  Absize = size(Absorbance) ;
  leg = Array{String}(length(Wavelength)) ;
  if Absize[1] > 1
    for i = 1:length(Wavelength)
      plot(AbsorbanceTime,Absorbance[:,i],figure=Absfig,dash_capstyle="round")
      leg[i] = string(Wavelength[i]," ","nm") ;
    end
    legend(leg)
    title("Absorbance vs time")
    xlabel("time (s)")
    ylabel("AU")
  else
    close(Absfig)
  end
  return nothing
end # plotdata function

The second figure, besides opening with a different logo than the first, doesn't respond and eventually crashes julia. Although I can simply create Absfig after evaluating the Balance values and solving the problem, before the last updates I never had this problem...

Did this happen to anyone? Thanks

MaxandreJ commented 6 years ago

This happens to me too. Very annoying.

MaxandreJ commented 6 years ago

More precisely, julia crashes when you open several figure windows, then close some, and select at figure windows you hadn't yet selected.

tkf commented 6 years ago

I can't reproduce any kind of crash but I can get a hang after closing the first window, when using TkAgg (not sure about other backend). It looks like the problem is that tkinter._default_root is None after closing the first figure:

julia> PyPlot.plt[:get_backend]()
"TkAgg"

julia> close("all")

julia> figure(1)
       plot([1,2,3])
       figure(2)
       plot([1,2,3])
       @show pyimport("tkinter")["_default_root"]
       close(1)
       @show pyimport("tkinter")["_default_root"];
(pyimport("tkinter"))["_default_root"] = PyObject <tkinter.Tk object .>
(pyimport("tkinter"))["_default_root"] = PyObject None

Not sure how to fix it though. TkAgg works in IPython. It looks like IPython uses tkinter._default_root.createfilehandler in non-Windows Tk. Maybe this is a better API to use? https://github.com/ipython/ipython/blob/7.0.1/IPython/terminal/pt_inputhooks/tk.py

tkf commented 6 years ago

https://github.com/JuliaPy/PyCall.jl/pull/591 fixes the problem with TkAgg.

MaxandreJ commented 6 years ago

Thanks a lot @tkf for your quick response! It works now! I'm glad this package is actively developed, I'm going to post other issues then! :-) And yes you are right julia did not "crash", it rather "hung", I lacked the proper technical term!