PyPlot won't close first figure drawn

715 views
Skip to first unread message

le...@neilson-levin.org

unread,
Nov 9, 2015, 1:55:50 PM11/9/15
to julia-users
Not getting any answers to a weird problem.

PyPlot won't close the first figure it creates.  Subsequent figures can be created and closed.  gcf will not return a valid id for the first figure drawn.  plt[:get_fignums]() won't return a value for the first figure (e.g.--the first figure is not included in the returned vector of figures).  The only way to close the orphaned figure is to exit Julia.  Further if you click on the figure window and try to manually close it you will get an infinite spinning beach ball.  You can, however, switch back to Julia repl, which is happily running just fine.

This is part of a script that draws figures with interactive on and clears them with a user prompt. It is sort of annoying that the first one can never be closed.  The same symptom can be observed using Julia interactively:

using PyPlot
plot(1:5)  # -> figure draws fine in a tk window
close() # -> nothing happens
scatter(rand(25),rand(25)) # -> draws just fine
close() #-> closes the scatter as you'd expect and only the first figure remains
close() # -> nothing happens

You can explicitly create the first figure with figure() or figure(1) and the same problem occurs.

Environment:
    os x 10.11.1 ("el capitan")
    python 2.7.10 from www.python.org
    matplotlib 1.5.0 and dependencies (via pip)
    numpy 1.10.1 (via pip)
    Julia 0.4.0
    latest PyCall & PyPlot (with backend :tk)
    xquartz 2.7.8 (latest per "upgrade..." on about box)
    tk 8.5.18 (latest from ActiveState)

This does not occur when conda installs its own Python--same version, except built by Continuum, with equivalent versions of all Python packages  I don't consider just using conda an appropriate solution, as that seems to be avoiding finding an answer.  As of 2 weeks ago there was no problem so something (not clear what) changed in the mean time.  There is a path to this Python as: /Library/Frameworks/Python.framework/Versions/2.7/bin which is the first directory in PATH. (Note: this is NOT the system python which is at /system/library/...).  Also, I can't switch to Winston or Gadfly as I need surface plots and contour plots--PyPlot to matplotlib is the only way to create these from Julia that I am aware of.

When installing PyCall and PyPlot the comment output identifies this version of Python.

I am trying to sort out the figure logic in PyPlot.jl but it is hard for me to figure (no pun intended) it out.

Of course, I'll provide any and all additional information about my configuration, etc and can try other things to help diagnose this weird thing.

Thanks,
Lewis

Ethan Anderes

unread,
Nov 9, 2015, 2:07:50 PM11/9/15
to julia-users

I have noticed something similar.

For example, if I do:

julia> using PyPlot

julia> figure(1)

julia> plot(sin(1:10))

julia> figure(2)

julia> plot(cos(1:10))

then close the first figure (by clicking the red button with my mouse) I get a spinning beach ball. I’m on OSX 10.11.1 using Anaconda python. PyPlot is at version "PyPlot"=>v"2.1.1+" and my system info is

julia> versioninfo()
Julia Version 0.4.1-pre+16
Commit 2cdef5d (2015-10-24 06:33 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin15.0.0)
  CPU: Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.3


le...@neilson-levin.org

unread,
Nov 10, 2015, 1:34:46 PM11/10/15
to julia-users
I'd still really like help with this.

Here are some possible problems with the way just the first figure is being handled within PyPlot:
 1.    being put in the figure_queue, which holds figures for IJulia--this shouldn't be happening as I am not using IJulia in this case;
 2.   somehow matplotlib is losing it: the close() function in PyPlot is a straightforward pycall to put[:close]--with a figure argument f.  But, when you plot without defining a figure first there is no figure to reference.  Calls to close don't pass any argument.  It's not clear why this would be a problem because everything works for the 2nd and all subsequent plots created WITHOUT first starting an identified figure.  
3.  gcf() can't find the figure.  When I run gcf after the first plot, it actually creates a NEW figure because it doesn't see that any figure exists (even though it is there because matplotlib created it and it's on the screen in a tk window).

So, number 3 seems to point to the symptom that in the handoff between matplotlib and pyplot, the first figure created is getting lost.  Perhaps someone can point me to the next level so I can keep trying to diagnose this.

It seems folks aren't so interested in problems that are rarely seen and are reported by Noobs.  We were all once noobs. I may be a permanent noob.  I realize there are cooler things to focus on in the future trajectory of Julia, but this is an actual problem.

Tom Breloff

unread,
Nov 10, 2015, 1:50:04 PM11/10/15
to julia-users
Lewis:  There are a couple things to note:
  • This belongs as a PyPlot issue... it's not really appropriate for julia-users
  • I think people have been slow to help you, not because you're a "noob", but because of your extreme negativity so far.
You've spent enough time on this that you're probably also the most qualified to solve it.

le...@neilson-levin.org

unread,
Nov 10, 2015, 2:09:06 PM11/10/15
to julia-users
I posted as an issue over on PyPlot.  I got a reply about Python but not about the problem.

Please point out how I have been negative.  I've tried to provide information and one other user confirms that he has also seen the problem.  I thought I was being pretty clear to just ask for clues or pointers to other things I can try or look at it.
Reply all
Reply to author
Forward
0 new messages