Automatically insert variable name or symbol in Title and Colorbar

Never had a reason to use macros before but I really liked @jules simple example above and wanted to try.

Maybe this would work for you @raman_kumar if you wrap your plotting code similarly?

using GLMakie

ψ = rand(100)
χ = rand(100)

function m(s::Symbol, values)
	exp_val = exp.(values)
	fig, ax, plt = scatter(exp_val)
	ax.title = "Plot of $s"
	return fig, ax, plt
end

macro m(variable::Symbol)
	:(m($(QuoteNode(variable)), $(esc(variable))))
end

fig1, ax1, plt1 = @m ψ
fig2, ax2, plt2 = @m χ
2 Likes