Getting Franklin.jl to display plots with Literate.jl

I’m following these instructions on getting Franklin.jl to deploy Julia notebooks with Literate.jl with GitHub pages. I’m using the following minimal example from the Literate.jl documentation:

# Testing plot display:
x = range(0, stop=6π, length=1000)
y1 = sin.(x)
y2 = cos.(x)
plot(x, [y1, y2])

Instead of displaying the plot on my site, I get the following output:

Plot{Plots.GRBackend() n=2}

Everything else is working fine - I’m using @def showall = true, and blocks that end with non-plotting commands display the correct output.

Please let me know if I’ve fundamentally misunderstood something! This is my first post on Discourse, so I appreciate your patience and help.

1 Like

Hello @mattgiamou , apologies for not responding earlier.

For plots, Franklin can work with physical files (actual .jpeg or .png or whatever). So you just need to save your plot and point to it.

What happens in your case is that Franklin applies a basic ‘show’ method to the last object, and in this case it just shows the name of the object. There could be a fallback detecting the MIME type of the object and trying to display a PNG rendered version of the plot but it’s not there yet.

What you have to do now

add a couple of lines of code to save the figure explicitly and then load that image.

Here’s an example of how you could do this:

the ‘output’ macro is there to help you get an automatic path for saving files. You don’t have to use it and could use an explicit path yourself if you preferred.


Thank you for the prompt and detailed response @tlienart! Franklin is fantastic software, can’t wait to continue playing around with it.