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

Generating ElectronPlot/ saving plots from Jupyter Notebook #88

Closed
piever opened this issue Oct 18, 2016 · 13 comments
Closed

Generating ElectronPlot/ saving plots from Jupyter Notebook #88

piever opened this issue Oct 18, 2016 · 13 comments

Comments

@piever
Copy link
Member

piever commented Oct 18, 2016

First of all, thanks for this amazing package. I'm using it mainly from Jupyter Notebook: it works very well but I'm having trouble saving the plots with savefig in any format except html. This works:

using PlotlyJS
trace = scatter(; x = rand(10), y = rand(10), mode = "markers")
p = plot(trace)
savefig(p,"test.html")

whereas any other format to save the file, i. e.

using PlotlyJS
trace = scatter(; x = rand(10), y = rand(10), mode = "markers")
p = plot(trace)
savefig(p,"test.svg")

tries opening an electron plot and then crashes. The issues seems to be opening the electronplot, as I get the same behavior if I try:

using PlotlyJS
trace = scatter(; x = rand(10), y = rand(10), mode = "markers")
p = plot(trace)
ElectronPlot(p)

So I wanted to ask: is there any way of creating ElectronPlot from jupyter and if there isn't, what is the recommended way of getting the svg/ pdf version of the plot?

@sglyon
Copy link
Member

sglyon commented Oct 19, 2016

Hi @piever I'm sorry it has been giving you issues.

Ideally this is what should be happening when you call savefig(p, "filename") in the juptyer notebook and the filename doesn't end in .html:

  • An ElectronPlot is created behind the scenes
  • The plot is loaded into an Electron window, but one that is never visible on your computer
  • The data needed to save the file is transferred from Electron back to Julia
  • The ghost window is closed
  • The data is converted into the file you asked for.

All of these steps are executing, but for some reason somewhere along the pipeline things get stuck. At not point it was working correctly, but one of the involved technologies must have made a change that is causing the issues we are seeing.

I did try this, however, and it worked for me from within the notebook:

_p = ElectronPlot(p)
display(_p)
savefig(_p, "my_file.pdf")
close(_p)

Note that this will bring up an electron window for a few seconds while the file data was extracted from electron.

I believe there are other packages in development right now that should make this processes much smoother.

cc @MikeInnes @shashi

@piever
Copy link
Member Author

piever commented Oct 19, 2016

I see, thanks for looking into this. I was trying something similar, and at least on my machine if

_p = ElectronPlot(p)

is the last line of code in the block, the program would freeze, whereas

 _p = ElectronPlot(p)
display(_p)

works. I was actually seeing something similar when trying it from Juno. I'm not sure I understand what it is, is it some sort of "REPL-like" behaviour of the notebook?

Your solution works on my machine as well (except if I try to do it repeatedly with plots with a different number of traces, for some reason).

@sglyon
Copy link
Member

sglyon commented Oct 21, 2016

That's very strange.

I believe this is an issue in Blink.jl or one of its dependencies. I'm pretty sure these issues will get attention soon -- so I think we'll just have to hang in there for now. (sorry, not a great answer -- but I don't have the extra time right now to implement a proper fix)

@amellnik
Copy link

On current latest tagged with

_p = ElectronPlot(p)
display(_p)
savefig(_p, "Yield vs config.svg")
close(_p)

I'm getting

MethodError: no method matching write(::IOStream, ::Dict{String,Any})
Closest candidates are:
  write(::IO, ::Any) at io.jl:146
  write(::IO, ::Any...) at io.jl:148
  write(::IOStream, ::Char) at iostream.jl:175
  ...

 in write(::IOStream, ::Dict{String,Any}) at .\io.jl:146
 in open(::PlotlyJS.##178#181, ::String, ::String) at .\iostream.jl:113
 in #savefig#175(::Symbol, ::Function, ::PlotlyJS.SyncPlot{PlotlyJS.ElectronDisplay}, ::String) at C:\Users\amellnik\.julia\v0.5\PlotlyJS\src\savefig.jl:130
 in savefig(::PlotlyJS.SyncPlot{PlotlyJS.ElectronDisplay}, ::String) at C:\Users\amellnik\.julia\v0.5\PlotlyJS\src\savefig.jl:106

Has the recommended method of doing this changed?

@sglyon
Copy link
Member

sglyon commented Apr 14, 2017

Hmm that is strange. The recommended way for saving a plot to a file is still the same.

I recently merged a fairly large set of changes. It is possible that this will work again on the current master branch. If you want to try it out now you can do Pkg.checkout("PlotlyJS").

Otherwise I will try to find time to put together a new release soon.

@amellnik
Copy link

amellnik commented Apr 14, 2017

I needed to manually build after checking out the latest master, but now I'm seeing something different -- running the code snippet above spawns an Electron window but then the process stalls out with Julia + two Electron processes taking up a full core.

image

I actually saw this on the PlotlyJS latest tagged after I checked out the ImageMagick master and updating everything (which got rid of the error above).

@sglyon
Copy link
Member

sglyon commented Apr 14, 2017

Hmm, that is very strange. I can't reproduce that locally. Sorry I'm not more help with that right now.

I'm in the middle of preparing a release based on the latest master (with a few more updates/fixes). I'll post here when that happens and kindly ask you to please try again.

@amellnik
Copy link

Sounds good, thanks!

@sglyon
Copy link
Member

sglyon commented Apr 14, 2017

Ok the new version has been tagged. Can you try

Pkg.free("PlollyJS")
Pkg.upate()
Pkg.build("PlotlyJS")

And then your test script.

Thank you -- fingers crossed that it works!

@amellnik
Copy link

I'm seeing the same thing on the latest tagged. I am using ImageMagick master due to some requirements issues if that makes any difference. The script stalls out at the _p = ElectronPlot(p) step.

There's a small chance this is related to some corporate proxy issue with the communication between the electron window and Julia but I don't think so -- Blink.jl seems to be working OK. I'll check at home this evening just to be sure.

@sglyon
Copy link
Member

sglyon commented Dec 13, 2017

Closing due to inactivity. Please re-open if this is still an issue we can help with

@sglyon sglyon closed this as completed Dec 13, 2017
@amellnik
Copy link

Just FYI, things like

using PlotlyJS

function bar1()
    data = bar(;x=["giraffes", "orangutans", "monkeys"],
                y=[20, 14, 23])
    plot(data)
end
p = bar1()

savefig(p, "Test.svg")

now work without any issues on latest tagged from a Juypter notebook!

@sglyon
Copy link
Member

sglyon commented Dec 18, 2017

Excellent!

Thanks for the report.

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