Closed lyonsquark closed 4 years ago
Thank you for reporting.
The show(io::IO, ::MIME"image/svg+xml"
method actually writes a svg
file, not an html
, so I can't change that.
The workaround you proposed works since, apparently, JupyterLab properly detects and display the svg
image even if an html
was required.
A possible solution is to implement a separate show(io::IO, ::MIME"text/html"
method using the canvas
terminal provided by gnuplot. I already prepared a branch. You can test it with:
add Gnuplot#testCanvasTerminal
and create plots as you normally do.
In this branch there is a new option, Gnuplot.options.term_html
, wth default value canvas mousing
. If you still prefer using a svg
file in JupyterLab you can change it as follows:
Gnuplot.options.term_html = "svg enhanced mouse size 700,500 lw 1";
Thanks! Trying it...
You likely know this already, but I was wondering how IJulia figured out what MIME type to display. I found the priority list... https://github.com/JuliaLang/IJulia.jl/blob/8c0f770309c88db402f5ed737ef7ae4312772fa7/src/inline.jl#L5-L20
No I didn't know it, thank you!
This means the changes in testCanvasTerminal
would also affect IJulia users....
Let's fix the problem with JupyterLab, then I'll think how to make everything flexible so that a user can choose the preferred terminal for images to be exported in the IDE.
Please confirm if the new branch works properly in JupyterLab. Thanks!
Ok - I have good news and bad news. Setting Gnuplot.options.term_html = "svg enhanced mouse size 700,500 lw 1";
works great.
The default Gnuplot.options.term_html = "canvas mousing"
does not work at all. I just get a blank square. I think is because the html that Gnuplot writes is not embeddable without putting it within an <iframe>
. The canvas
terminal has a default option standalone
that makes a full html file (including <!DOCTYPE HTML>
). The alternate option, name
, writes straight javascript to the output file. You would need to write an html wrapper to make that work.
I think a good solution is to just use svg. That works well.
Also, you should change the extension of the temp file for text/html
to .html
. Not that it really matters, but it makes more sense than .png
.
I added the changes in the master branch, and deleted the testCanvasTerminal
branch:
]add Gnuplot#master
I also changed the way terminal options are specified. In your case:
Gnuplot.options.mime[MIME"text/html"] = "svg enhanced mouse size 700,500 lw 1"
Default value is svg enhanced dynamic
, which is supposed to work without problems for the majority of users.
You may explicitly preview what is being passed to JupyterLab with, e.g.
@gp 1:9
save(MIME"text/html", output="tmp.svg")
Thanks! Trying it now.
I can confirm this now works! Thanks very much!!
I wrote too soon - multiplot
doesn't work. I'll open a new issue and look at it.
Hi! Thanks for making gnuplots show up in Jupyter notebooks! If I turn on
enhanced mouse
for thesvg
terminal,the expected tool tips don't work in the plot output in JupyterLab. This apparently is a known issue (or maybe feature) - see https://github.com/jupyterlab/jupyterlab/issues/7497 . The workaround is to give Jupyter a
text/html
MIME type instead ofimage/svg+xml
. I tried this in my dev version of the package. On line https://github.com/gcalderone/Gnuplot.jl/blob/bad5e12681960a9cf4eac526c36685421638bcb3/src/Gnuplot.jl#L1520 I replaced::MIME"image/svg+xml"
with::MIME"text/html"
. The plot appears correctly and tool tips work!I have no idea if this will affect Juno or other editors. But it works for JupyterLab. Since this is such a small change, I don't think it deserves a full pull request, but I can submit one if you'd like. I'm worried about side-effects though for other systems. -- Adam