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

Plots in notebook #242

Open
truefalsename opened this issue Oct 11, 2018 · 10 comments
Open

Plots in notebook #242

truefalsename opened this issue Oct 11, 2018 · 10 comments

Comments

@truefalsename
Copy link

Hi,

I noticed that after the new update plots are shown on an external electron window. Is there a way to have them shown in a cell of a jupyter notebook instead?

Thanks

@sglyon
Copy link
Member

sglyon commented Oct 15, 2018

Hi @truefalsename sorry about that. I will investigate and report back in the next couple days

@truefalsename
Copy link
Author

Hello,

thanks. A bit more of puzzling info: not all the plots open in a separate window, most open correctly inline. The only one that is display in an electron window is based on the quiver function I made:

function plot_v_slice(res::DataFrame, n::Int, ax::String, min::Float64, max::Float64; scale = 1.0)
 """
Fuction to plot velocity maps for a slice between min and max along ax",

Inputs:
      - res:: Dataframe for cells properties
      - n:: minimum number of stars in cell
      - ax:: x, y or z
      - min, max:: edges of the desired slice

Kwargs:
      - scale:: magnification factor for the arrow lengths 
"""   

if ax == "z"

    # cells in slice
    
    res_slice = res[.&(res[:n_star] .> n-1, res[:z_cell] .>= min, res[:z_cell] .<= max) , :]

    xmin = floor(minimum(collect(res_slice[:x_cell])))
    xmax = ceil(maximum(collect(res_slice[:x_cell])))

    ymin = floor(minimum(collect(res_slice[:y_cell])))
    ymax = ceil(maximum(collect(res_slice[:y_cell])))


    # Galactic Centre

    t0 = scatter(; x = [0], y = [0], mode = "markers",
                 marker = attr(color = "#000000", size = 8, symbol = "o", opacity = 1))

    #Cells

     t1 = scatter(;  x = collect(res_slice[:x_cell]), 
                     y = collect(res_slice[:y_cell]), 
                     mode = "markers",
                     marker = attr(color = "#47d157", size = 8, symbol = "circle", opacity = 0.85),
                     text = ["n stars: $k <br>u: $(round(i, digits = 2)) km/s <br>v: $(round(j, digits=2)) km/s" for (i,j,k)
                            in zip(collect(res_slice[:u_mean]),collect(res_slice[:v_mean]),collect(res_slice[:n_star]))]
        )


    # velocities array
    vels = [attr(
            x = star[:x_cell] + scale * star[:u_mean], 
            y = star[:y_cell] + scale * star[:v_mean],
            showarrow = true,
            axref = "x",
            ayref = "y",
            arrowcolor = "#707070",
            arrowhead = 3,
            ax = star[:x_cell], 
            ay = star[:y_cell])
    for star in DataFrames.eachrow(res_slice)]


    layout = Layout(; 
                autosize = false, width = 800, height = 800, 
                margin = attr(l = 50, r = 50, b = 50, t = 50),
                showlegend = false,
                title = "velocity field section; $(min)<$(ax)<$(max)",
                annotations = vels,
                xaxis = attr(title = "xGC [pc]"),
                yaxis = attr(title = "yGC [pc]"),
                )

    plot([t0, t1], layout)
    
elseif ax == "y"
    
    # cells in slice
    
    res_slice = res[.&(res[:n_star] .> n-1, res[:y_cell] .>= min, res[:y_cell] .<= max) , :]

    xmin = floor(minimum(collect(res_slice[:x_cell])))
    xmax = ceil(maximum(collect(res_slice[:x_cell])))

    ymin = floor(minimum(collect(res_slice[:z_cell])))
    ymax = ceil(maximum(collect(res_slice[:z_cell])))


    # Galactic Centre

    t0 = scatter(; x = [0], y = [0], mode = "markers",
                 marker = attr(color = "#000000", size = 8, symbol = "o", opacity = 1))

    #Cells

     t1 = scatter(;  x = collect(res_slice[:x_cell]), 
                     y = collect(res_slice[:z_cell]), 
                     mode = "markers",
                     marker = attr(color = "#47d157", size = 8, symbol = "circle", opacity = 0.85),
                     text = ["n stars: $k <br>u: $(round(i, digits = 2)) km/s<br>w: $(round(j, digits=2)) km/s" for (i,j,k)
                            in zip(collect(res_slice[:u_mean]),collect(res_slice[:w_mean]),collect(res_slice[:n_star]))]

        )


    # velocities array
    vels = [attr(
            x = star[:x_cell] + scale * star[:u_mean], 
            y = star[:z_cell] + scale * star[:w_mean],
            showarrow = true,
            axref = "x",
            ayref = "y",
            arrowcolor = "#707070",
            arrowhead = 3,
            ax = star[:x_cell], 
            ay = star[:z_cell])
    for star in DataFrames.eachrow(res_slice)]


    layout = Layout(; 
                autosize = false, width = 800, height = 800, 
                margin = attr(l = 50, r = 50, b = 50, t = 50),
                showlegend = false,
                title = "velocity field section; $(min)<$(ax)<$(max)",
                annotations = vels,
                xaxis = attr(title = "xGC [pc]"),
                yaxis = attr(title = "zGC [pc]"),
                )

    plot([t0, t1], layout)
    
    
elseif ax == "x"
    
    # cells in slice
    
    res_slice = res[.&(res[:n_star] .> n-1, res[:x_cell] .>= min, res[:x_cell] .<= max) , :]

    xmin = floor(minimum(collect(res_slice[:z_cell])))
    xmax = ceil(maximum(collect(res_slice[:z_cell])))

    ymin = floor(minimum(collect(res_slice[:y_cell])))
    ymax = ceil(maximum(collect(res_slice[:y_cell])))


    # Galactic Centre

    t0 = scatter(; x = [0], y = [0], mode = "markers",
                 marker = attr(color = "#000000", size = 8, symbol = "o", opacity = 1))

    #Cells

     t1 = scatter(;  x = collect(res_slice[:z_cell]), 
                     y = collect(res_slice[:y_cell]), 
                     mode = "markers",
                     marker = attr(color = "#47d157", size = 8, symbol = "circle", opacity = 0.85),
                     text = ["n stars: $k <br>v: $(round(i, digits = 2)) km/s <br>w: $(round(j, digits=2)) km/s" for (i,j,k)
                            in zip(collect(res_slice[:v_mean]),collect(res_slice[:w_mean]),collect(res_slice[:n_star]))]
        )


    # velocities array
    vels = [attr(
            x = star[:z_cell] + scale * star[:w_mean], 
            y = star[:y_cell] + scale * star[:v_mean],
            showarrow = true,
            axref = "x",
            ayref = "y",
            arrowcolor = "#707070",
            arrowhead = 3,
            ax = star[:z_cell], 
            ay = star[:y_cell])
    for star in DataFrames.eachrow(res_slice)]


    layout = Layout(; 
                autosize = false, width = 800, height = 800, 
                margin = attr(l = 50, r = 50, b = 50, t = 50),
                showlegend = false,
                title = "velocity field section; $(min)<$(ax)<$(max)",
                annotations = vels,
                xaxis = attr(title = "zGC [pc]"),
                yaxis = attr(title = "yGC [pc]"),
                )

    plot([t0, t1], layout)
    
end

end

The test function I have provided however does not have this problem.

@sglyon
Copy link
Member

sglyon commented Oct 31, 2018

Hi @truefalsename I just tried it out and didn't have any problems getting my plot to display in the notebook.

Is this still a problem for you?

If it is, would you please provide a minimal example that I could use to try to reproduce the issue?

Thank you

@YermolenkoIgor
Copy link

Hello! Have problem with simple plot:
julia> using Plots

julia> plotlyjs()
[ Info: Recompiling stale cache file C:\Users\Игорь.julia\compiled\v1.0\PlotlyJ
S\1r9Ld.ji for PlotlyJS [f0f68f2c-4968-5e81-91da-67840de0976a]
WARNING: could not import Base.quit into AtomShell
[ Info: Recompiling stale cache file C:\Users\Игорь.julia\compiled\v1.0\ORCA\jv
X7k.ji for ORCA [47be7bcc-f1a6-5447-8b36-7eeeff7534fd]
Plots.PlotlyJSBackend()
julia> plot([1; 2], [3; 4])
Error showing value of type Plots.Plot{Plots.PlotlyJSBackend}:
ERROR: Cannot find Electron. Try Blink.AtomShell.install().
Stacktrace:
[1] error(::String) at .\error.jl:33
[2] electron at C:\Users\Игорь.julia\packages\Blink\vKGzM\src\AtomShell\proces
s.jl:62 [inlined]
[3] #init#6(::Bool, ::Function) at C:\Users\Игорь.julia\packages\Blink\vKGzM\s
rc\AtomShell\process.jl:80
[4] #init at .\none:0 [inlined]
[5] #shell#9(::Bool, ::Function) at C:\Users\Игорь.julia\packages\Blink\vKGzM
src\AtomShell\process.jl:123
[6] shell at C:\Users\Игорь.julia\packages\Blink\vKGzM\src\AtomShell\process.j
l:121 [inlined]
.........................................
(v1.0) pkg> build Blink
Building MbedTLS → C:\Users\Игорь\.julia\packages\MbedTLS\eaAxb\deps\build.lo g
Building WebIO ──→ C:\Users\Игорь\.julia\packages\WebIO\myl19\deps\build.log
julia> using Blink

julia> Blink.AtomShell.install()
ERROR: IOError: could not spawn 7z x electron-v2.0.5-win32-x64.zip -oatom: no
such file or directory (ENOENT)
Stacktrace:
[1] _jl_spawn(::String, ::Array{String,1}, ::Cmd, ::Tuple{RawFD,RawFD,RawFD}) a
t .\process.jl:367
[2] (::getfield(Base, Symbol("##494#495")){Cmd})(::Tuple{RawFD,RawFD,RawFD}) at
.\process.jl:509
[3] setup_stdio(::getfield(Base, Symbol("##494#495")){Cmd}, ::Tuple{RawFD,RawFD
,RawFD}) at .\process.jl:490
[4] #_spawn#493(::Nothing, ::Function, ::Cmd, ::Tuple{RawFD,RawFD,RawFD}) at .
process.jl:508
[5] _spawn at .\process.jl:504 [inlined]
[6] #run#504(::Bool, ::Function, ::Cmd) at .\process.jl:662
[7] run at .\process.jl:661 [inlined]
[8] (::getfield(Blink.AtomShell, Symbol("##1#2")))() at C:\Users\Игорь.julia\p
ackages\Blink\vKGzM\src\AtomShell\install.jl:48
[9] cd(::getfield(Blink.AtomShell, Symbol("##1#2")), ::String) at .\file.jl:85
[10] install() at C:\Users\Игорь.julia\packages\Blink\vKGzM\src\AtomShell\inst
all.jl:27
[11] top-level scope at none:0
(v1.0) pkg> status
Status C:\Users\Игорь\.julia\environments\v1.0\Project.toml
[537997a7] AbstractPlotting v0.9.0
[ad839575] Blink v0.8.1
[159f3aea] Cairo v0.5.6
[5ae59095] Colors v0.9.5
[8f4d0f93] Conda v1.1.1
[0c46a032] DifferentialEquations v5.3.1
[a1bb12fb] Electron v0.2.0
[5789e2e9] FileIO v1.0.2
[5752ebe1] GMT v0.5.0
[28b8d3ca] GR v0.35.0
[c91e804a] Gadfly v1.0.0+ #master (https://github.com/GiovineItalia/Gadfly.jl.
git)
[4c0ca9eb] Gtk v0.16.4
[a1b4810d] Hexagons v0.2.0
[7073ff75] IJulia v1.13.0+ [C:\Users\Игорь\.julia\dev\IJulia]
[6218d12a] ImageMagick v0.7.1
[c601a237] Interact v0.9.0
[ee78f7c6] Makie v0.9.0+ #master (https://github.com/JuliaPlots/Makie.jl.git)
[7269a6da] MeshIO v0.3.1
[47be7bcc] ORCA v0.1.1
[58dd65bb] Plotly v0.2.0
[f0f68f2c] PlotlyJS v0.11.2+ #master (https://github.com/sglyon/PlotlyJS.jl.gi
t)
[91a5bcdd] Plots v0.21.0
[c4c386cf] Rsvg v0.2.2
[60ddc479] StatPlots v0.8.1
[b8865327] UnicodePlots v0.3.1
[0f1e0344] WebIO v0.4.0
[c2297ded] ZMQ v1.0.0

@YermolenkoIgor
Copy link

Problem for Jupyter notebook

using Plots

plotlyjs()
out Plots.PlotlyJSBackend()

x = 1:10; y = rand(10); # These are the plotting data
plot(x,y)

UndefVarError: _use_remote not defined

Stacktrace:
[1] _show(::Base.GenericIOBuffer{Array{UInt8,1}}, ::MIME{Symbol("text/html")}, ::Plots.Plot{Plots.PlotlyJSBackend}) at C:\Users\Игорь.julia\packages\Plots\rmogG\src\backends\plotlyjs.jl:54
[2] show(::Base.GenericIOBuffer{Array{UInt8,1}}, ::MIME{Symbol("text/html")}, ::Plots.Plot{Plots.PlotlyJSBackend}) at C:\Users\Игорь.julia\packages\Plots\rmogG\src\output.jl:201
[3] #sprint#325(::Nothing, ::Int64, ::Function, ::Function, ::MIME{Symbol("text/html")}, ::Vararg{Any,N} where N) at .\strings\io.jl:101
[4] sprint(::Function, ::MIME{Symbol("text/html")}, ::Vararg{Any,N} where N) at .\strings\io.jl:97
[5] display_dict(::Plots.Plot{Plots.PlotlyJSBackend}) at C:\Users\Игорь.julia\packages\Plots\rmogG\src\init.jl:76
[6] #invokelatest#1 at .\essentials.jl:697 [inlined]
[7] invokelatest at .\essentials.jl:696 [inlined]
[8] execute_request(::ZMQ.Socket, ::IJulia.Msg) at C:\Users\Игорь.julia\dev\IJulia\src\execute_request.jl:256
[9] #invokelatest#1 at .\essentials.jl:697 [inlined]
[10] invokelatest at .\essentials.jl:696 [inlined]
[11] eventloop(::ZMQ.Socket) at C:\Users\Игорь.julia\dev\IJulia\src\eventloop.jl:8
[12] (::getfield(IJulia, Symbol("##12#15")))() at .\task.jl:259

@sglyon
Copy link
Member

sglyon commented Oct 31, 2018

Thanks for contributing @YermolenkoIgor

This is an issue with Plots.jl, not PlotlyJS.jl

We are hoping to address this soon and get Plots + PlotlyJS working again. I've looked into the issue and will need a little bit of help from WebIO experts like @shashi, but we'll get it sorted out soon!

@truefalsename
Copy link
Author

Hey,

sorry for the late reply. The problem remains after updating everything to the newest release
. I am attaching a strip down version of the notebook I am using. The first plotting function (v_slice I believe) opens an external julia window. The remaining two functions are correctly visualised in the notebook.
Archive.zip

@sglyon
Copy link
Member

sglyon commented Dec 3, 2018

Hi @truefalsename is this a problem still?

Thanks

@truefalsename
Copy link
Author

Hello,

sorry for the late reply: i changed computer moving to windows.
Yes, it still happens

@truefalsename
Copy link
Author

Btw, I noticed also another thing: I cannot interact with 3d plots anymore. I am using the same code as on my old mac, the plots display in notebook (not the arrows one, that is still in the atom window) but they are rather buggy: cannot rotate them with the mouse and annotations are stuck to the first object I hover on. Has this something to do with the WebIO issue? I tried to downgrade and pin WebIO but the same issue happens

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

3 participants