Weave.jl
Weave.jl copied to clipboard
Support GIF from Plots in markdown? with a scratch[FR]
If I save a gif in the folder or path the file goes
/```julia
p2 = Plots.plot!(xlim = (-2,2))
anm = @animate for i in 1:25
Plots.plot!(x->x^2/i,key = false)
Plots.title!("x-> (1/ $i) *(x^2)",key = false)
end
gif(anm,"xSqrDivByi.gif")
\```
\```
Plots.AnimatedGif("D:\\animated-adventure-in-mathematics\\ElementaryFnTrans
\\xSqrDivByi.gif")
\```
It seems possible to detect pwd(), which is
Plots.AnimatedGif("D:\\animated-adventure-in-mathematics\\ElementaryFnTrans
\
and just substitute it with

so that we can get support for gif link to this relev proj.
Just realized that the hard part is the line folds when it is too long. Maybe if we detect gif() usage it would be better
Btw, if you really need this, this hack ought to do (am currently using it myself):
using Plots
function Weave.WeavePlots.add_plots_figure(report::Weave.Report, plot::Plots.AnimatedGif, ext)
chunk = report.cur_chunk
full_name, rel_name = Weave.get_figname(report, chunk, ext = ext)
# A `AnimatedGif` has been saved somewhere temporarily, so make a copy to `full_name`.
cp(plot.filename, full_name; force = true)
push!(report.figures, rel_name)
report.fignum += 1
return full_name
end
function Base.display(report::Weave.Report, m::MIME"text/plain", plot::Plots.AnimatedGif)
Weave.WeavePlots.add_plots_figure(report, plot, ".gif")
end
or if you have a package which uses Weave.jl, in which you need the following:
using Requires, Plots
function __init__()
@require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" begin
# HACK
function Weave.WeavePlots.add_plots_figure(report::Weave.Report, plot::Plots.AnimatedGif, ext)
chunk = report.cur_chunk
full_name, rel_name = Weave.get_figname(report, chunk, ext = ext)
# A `AnimatedGif` has been saved somewhere temporarily, so make a copy to `full_name`.
cp(plot.filename, full_name; force = true)
push!(report.figures, rel_name)
report.fignum += 1
return full_name
end
function Base.display(report::Weave.Report, m::MIME"text/plain", plot::Plots.AnimatedGif)
Weave.WeavePlots.add_plots_figure(report, plot, ".gif")
end
end
end