PlotlyJS.jl icon indicating copy to clipboard operation
PlotlyJS.jl copied to clipboard

plotting svg

Open asbisen opened this issue 6 years ago • 1 comments

Wondering if such a snippet would come in handy to others? This plots the Plotly plots in SVG. Comes in handy when I export my notebooks to share with others using html.

function plot_svg(p::PlotlyJS.SyncPlot)
    fn,_ = mktemp()
    fn = join([fn, ".svg"])
    savefig(p, fn)
    open(fn) do f
        display("image/svg+xml", read(f, String))
    end
end

asbisen avatar Nov 05 '18 16:11 asbisen

Hi @asbisen looks cool.

I actually implemented some changes in ORCA that would allow you to write directly ot an iostream instead of only to a file so you could do something like this (untested)

function plot_svg(p::PlotlyBase.Plot)
    io = IOBuffer()
    savefig(io, p, format="svg")
    display("image/svg+xml", String(take!(io)))
end

plot_svg(p::PlotlyJS.SyncPlot) = plot_svg(p.plot)

sglyon avatar Nov 07 '18 15:11 sglyon