Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not compatible with latest matplotlib version #79

Closed
twmr opened this issue Aug 27, 2014 · 22 comments
Closed

not compatible with latest matplotlib version #79

twmr opened this issue Aug 27, 2014 · 22 comments

Comments

@twmr
Copy link

twmr commented Aug 27, 2014

I get the following exception when i try to execute (matplotlib version: 1.4/1.5.dev)

using PyPlot
x = linspace(0,2*pi,1000)
y = sin(3*x + 4*cos(2*x))
plot(x, y, color="red", linewidth=2.0, linestyle="--")
PyError (PyObject_Call) <type 'exceptions.TypeError'>
TypeError('Julia exception: TypeError(:draw_if_interactive,"if",Bool,0)',)
  File "/home/thomas/.local/lib/python2.7/site-packages/matplotlib-1.5.x-py2.7-linux-x86_64.egg/matplotlib/pyplot.py", line 3086, in plot
    ax = gca()
  File "/home/thomas/.local/lib/python2.7/site-packages/matplotlib-1.5.x-py2.7-linux-x86_64.egg/matplotlib/pyplot.py", line 827, in gca
    ax =  gcf().gca(**kwargs)
  File "/home/thomas/.local/lib/python2.7/site-packages/matplotlib-1.5.x-py2.7-linux-x86_64.egg/matplotlib/pyplot.py", line 461, in gcf
    return figure()
  File "/home/thomas/.local/lib/python2.7/site-packages/matplotlib-1.5.x-py2.7-linux-x86_64.egg/matplotlib/pyplot.py", line 450, in figure
    draw_if_interactive()

while loading In[1], in expression starting on line 4

 in pyerr_check at /home/thomas/.julia/PyCall/src/exception.jl:58
 in pycall at /home/thomas/.julia/PyCall/src/PyCall.jl:85
 in plot at /home/thomas/.julia/PyPlot/src/PyPlot.jl:290
@twmr twmr changed the title not compatible with the latest matplotlib version not compatible with latest matplotlib version Aug 27, 2014
@stevengj
Copy link
Member

This almost looks like pyplot.isinteractive() is returning 0 instead of a boolean value, or that PyCall is getting confused and converting to an integer for some reason. Check whether

using PyPlot
PyPlot.pltm[:isinteractive]()

returns a boolean.

A workaround would be to change line 168 of PyPlot.jl, in the definition of draw_if_interactive, from pltm[:isinteractive]() to pycall(pltm["isinteractive"], Bool).

@twmr
Copy link
Author

twmr commented Aug 27, 2014

Yes, it is indeed returning 0 (mpl 1.4) and true (mpl 1.3).

With your proposed workaround the exception is no longer thrown. However, no graph gets drawn in the notebook.

Here is my patch:

--- a/src/PyPlot.jl
+++ b/src/PyPlot.jl
@@ -162,13 +162,14 @@ svg(b::Bool) = (SVG[1] = b)

 Base.isempty(f::Figure) = isempty(pycall(f["get_axes"], PyVector))

 function draw_if_interactive()
     if isjulia_display[1]
-        if pltm[:isinteractive]()
+        if pycall(pltm["isinteractive"], Bool)
             manager = Gcf[:get_active]()
             if manager != nothing
                 fig = Figure(manager["canvas"]["figure"])

@stevengj
Copy link
Member

If it is returning 0 then there are two problems. First, it is returning an integer for some reason, although my suggestion above works around this. Second, the integer 0 corresponds to false so it doesn't think it is in interactive mode...

@stevengj
Copy link
Member

What operating system are you using? If you are on Linux, can you try using PyCall; pygui(:gtk); using PyPlot?

@dpsanders
Copy link

I was just about to report the same error... On MacOS. The above command you asked for returns 0.

PyError (PyObject_Call) <class 'TypeError'>
TypeError('Julia exception: TypeError(:draw_if_interactive,"if",Bool,0)',)
  File "/usr/local/Cellar/python3/3.4.1_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/pyplot.py", line 3086, in plot
    ax = gca()
  File "/usr/local/Cellar/python3/3.4.1_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/pyplot.py", line 827, in gca
    ax =  gcf().gca(**kwargs)
  File "/usr/local/Cellar/python3/3.4.1_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/pyplot.py", line 461, in gcf
    return figure()
  File "/usr/local/Cellar/python3/3.4.1_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/pyplot.py", line 450, in figure
    draw_if_interactive()

while loading In[3], in expression starting on line 1

 in pyerr_check at /Users/dsanders/.julia/v0.3/PyCall/src/exception.jl:58
 in pycall at /Users/dsanders/.julia/v0.3/PyCall/src/PyCall.jl:85
 in plot at /Users/dsanders/.julia/v0.3/PyPlot/src/PyPlot.jl:290
Julia Version 0.3.1-pre+39
Commit 1c757b1* (2014-08-26 20:37 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.1.0)
  CPU: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

@twmr
Copy link
Author

twmr commented Aug 27, 2014

I'm using Linux. No window pops up if i set the backend to 'gtk' and call plot.

@stevengj
Copy link
Member

Are you running in IJulia or the REPL?

@twmr
Copy link
Author

twmr commented Aug 27, 2014

IJulia - I started IJulia from the REPL. (notebook())

@stevengj
Copy link
Member

No window should pop up in IJulia unless you do pygui(true). Can you try it from the REPL?

@twmr
Copy link
Author

twmr commented Aug 27, 2014

pygui(true) has no effect.

julia> using PyPlot; pygui(true); plot(1:10)
INFO: Loading help data...
1-element Array{Any,1}:
 PyObject <matplotlib.lines.Line2D object at 0xa5e6150>  -> no window 

same with gtk backend (after a restart of julia):

julia> using PyCall; pygui(:gtk); using PyPlot; plot(1:10)
INFO: Loading help data...
1-element Array{Any,1}:
 PyObject <matplotlib.lines.Line2D object at 0x147a0fd0> -> no window

I also tried this

julia> using PyCall; pygui(:gtk); using PyPlot; pygui(true); plot(1:10)
INFO: Loading help data...
1-element Array{Any,1}:
 PyObject <matplotlib.lines.Line2D object at 0xa7fa250> -> no window

@freddycct
Copy link

I face the same problem, can please submit a fix soon?

@twmr
Copy link
Author

twmr commented Aug 28, 2014

I applied it to the code in .julia/PyPlot/... However, it still does not work
even with this patch.

On Thu, Aug 28, 2014 at 7:35 PM, Freddy Chua notifications@github.com
wrote:

I face the same problem, how do I apply the patch?


Reply to this email directly or view it on GitHub
#79 (comment).

@freddycct
Copy link

help... i updated matplotlib to 1.4 through homebrew on osx, now i cannot revert back to the old 1.3 and pyplot does not work as a result..

@dpsanders
Copy link

Maybe try uninstalling the brew one and then install 1.3 with pip:

pip install matplotlib==1.3.1

I had success with Python 2.7.8 and the corresponding pip installed from homebrew, and then the above pip command for matplotlib.

@dpsanders
Copy link

(after messing around with a lot of other combinations, none of which worked...)

@freddycct
Copy link

well, I removed the homebrew matplotlib 1.4, I am not able to get back the 1.3 version on homebrew, so i eventually install matplotlib using 1.3

I still hope stevengj quickly update PyPlot so that we can use it with matplotlib 1.4

@manuamador
Copy link

screen shot 2014-09-01 at 08 55 15

Same here, when using plot, a julia exec instance appears on OS X dock. But no GUI (forget the first error line in the capture above, I am not really awake this morning)
I reinstalled, PyQt, PySide first, to be sure...
But "savefig(filename)" works so I can check some png pictures of my work, but no zooming, panning through the plots...

@ackalker
Copy link

ackalker commented Sep 1, 2014

I'm having the same issue. If it is of any help (I believe in going back to basics to diagnose stuff), the simple matplotlib tutorial at http://nbviewer.ipython.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-4-Matplotlib.ipynb works with IPython (using the 'python' profile of course) and this new matplotlib version.

Using Arch Linux x86_64, python 3.4.1-1, python-matplotlib 1.4.0-1, i see:

In [1]: %matplotlib inline
In [2]: from pylab import *
In [3]: x = linspace(0, 5, 10)
        y = x ** 2
        figure()
        plot(x, y, 'r')
        xlabel('x')
        ylabel('y')
        title('title')
        show()

(plot is shown inline)

In [6]: mpl.is_interactive()
Out[6]: True

@stevengj
Copy link
Member

stevengj commented Sep 3, 2014

This seems to have gotten broken by matplotlib/matplotlib#2286 (subsequently further modified by matplotlib/matplotlib#2503). Basically, Matplotlib refuses to enable interactive mode because it thinks that Python is non-interactive.

@mdboom, the difficulty with these patches is that they assume that Matplotlib can only be used interactively via the python executable, whereas we are calling it via libpython in Julia.

A workaround would be for PyPlot to set sys.flags.interactive manually when it is loaded, but unfortunately it seems that the sys.flags.interactive attribute is read-only.

@stevengj
Copy link
Member

stevengj commented Sep 3, 2014

Looks like a workaround is for me to manually set sys.ps1 when PyPlot is loaded (before loading Matplotlib). A bit ugly, but it seems to work.

@gasagna
Copy link

gasagna commented Sep 4, 2014

Thanks, works like a charm now..

@manuamador
Copy link

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants