JuliaPy / PyPlot.jl

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

Plot displaying - just getting PyObject #337

Open davidzentlermunro opened 6 years ago

davidzentlermunro commented 6 years ago

I'm using julia v0.6.0 in atom v1.22.1. I've installed pyplot after running ENV["PYTHON"]="". If I run: using PyPlot plot(1:5,(1:5).^2) It returns a PyCall.PyObject and address, without displaying. Any ideas?

c42f commented 6 years ago

I've just encountered this problem on windows 10. It seems to be independent of the python environment; I've tried the interpreter installed automatically by Conda.jl, and also manually installed via the standard anaconda installer in both python2.7 and python 3.6 flavours.

I'm not sure why this is happening yet, but I found a workaround which is to call pygui(true):

using PyPlot
pygui(true)

plot(randn(100))
c42f commented 6 years ago

Further version information regarding my setup, and a more complete demo:

   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.2 (2017-12-13 18:08 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-w64-mingw32

julia> using PyPlot

julia> plot(randn(100))
1-element Array{PyCall.PyObject,1}:
 PyObject <matplotlib.lines.Line2D object at 0x000000002EFFCEB8>

julia> # ^ But no GUI window appears at this point

julia> pygui(true)
true

julia> # Still no plot window

julia> plot(randn(100))
Warning: QT_DEVICE_PIXEL_RATIO is deprecated. Instead use:
    QT_AUTO_SCREEN_SCALE_FACTOR to enable platform plugin controlled per-screen factors.
    QT_SCREEN_SCALE_FACTORS to set per-screen factors.
    QT_SCALE_FACTOR to set the application global scale factor.
1-element Array{PyCall.PyObject,1}:
 PyObject <matplotlib.lines.Line2D object at 0x0000000030F29C88>

julia> # Plot window magically arrives now!
c42f commented 6 years ago

Ok, here's why this was happening, at least for me.

Because I'm on windows 10, I've applied the workaround from https://github.com/JuliaPy/PyPlot.jl/issues/334#issuecomment-358551237 in order to pin to the old version 2.3.1.

But in julia-0.6 PyPlot.isdisplayok() from version 2.3.1 doesn't work due to https://github.com/JuliaPy/PyPlot.jl/issues/281.

So pygui(true) is a workaround for this odd combination of versions, I'm not sure it will work for you @davidzentlermunro ?

c42f commented 6 years ago

Furthermore, having manually installed python 3.6 via anaconda and set ENV["PYTHON"] to the appropriate path, I've been able to Pkg.free("PyPlot") which upgrades PyPlot to 2.3.2, and plotting is now working as expected.

namelessenko commented 2 years ago

thanks it helped me, I had the same problem

stevengj commented 2 years ago

Probably it just means that PyPlot is not finding a working backend. e.g. look at PyPlot.backend