Figure caption in Pluto

This may be obvious to Pluto users, but I was struggling for a while with creating captioned figures in Pluto notebooks. I used to have a cell with a Makie figure as output, followed by a Markdown cell containing the caption, but sometimes these would become separated as I worked on the notebook. Looking through the PlutoUI roadmap, there appears to be a plan to include captioned figures, but I couldn’t find anything that works now. So, the solution that worked for me was to interpolate the figure object in an md-string, as the following example shows:

### A Pluto.jl notebook ###
# v0.19.9

using Markdown
using InteractiveUtils

# ╔═╡ 5a71a298-1865-11ed-1107-59fe5409d584
begin
	using Makie
	using CairoMakie
end

# ╔═╡ ddb846a3-12ce-46e0-b597-7a837f97a051
let
	x = range(0,stop=1.0, length=20)
	fig = Figure(resolution=(500,500))
	ax = Axis(fig[1,1])
	lines!(ax, x, x.^2)
	md"""
	$(fig)
	**Figure 1** This is a caption
	"""
end

As I said, it is kind of an obvious solution, but I thought I’d leave it here in case someone finds it useful.

6 Likes