The documentation mentions a plot_title attribute which has not yet been implemented, but I assume it will be eventually. In the meantime, you can use a subplot containing only a title as a workaround:
Has anyone developed a better solution? The reported solutions require a lot of manual adjustment of the margins and can result in truncation of subplots.
@Christopher_Fisher, could you provide an example of the truncation observed?
Herein a variant of the last solution, in case it might work better for your use case:
using Measures, Plots; gr()
l = @layout [a{0.01h}; grid(2,2)]
p = fill(plot(),5,1)
p[1] = plot(title="Supertitle",framestyle=nothing,showaxis=false,xticks=false,yticks=false,margin=0mm)
[p[i+1] = plot(1:10,rand(10),framestyle=:default,lc=rand(1:20),label="$i",title="title $i") for i in 1:4]
plot(p..., layout=l)
I think there were a few issues. First, bottom_margin = -50Plots.px from kdyhage’s code was causing truncation. I set this value to zero to fix that problem. I’m not sure if that might be useful in other cases. I also encountered some issues with subtitles being placed on top of the x-axis title of the plot above. I solved that with margin=10mm. I’m not sure why that happens in some cases but not others. Sorry that I do not have examples of the problem that can be shared. In any case, modifying those two parameters may help others in the future.
I think you can’t with plot_title (yet), but I may be wrong. If you want to have more control on the position, I still think @rafael.guerra is the best solution.
Actually it is possible to control the “vspan” of the plot_title with the plot_titlevspan attritbute which takes a number in the interval [0,1] defining the percentage of the figure that has to be reserved for the title.
As an extreme example:
using Plots
p1 = scatter(rand(5, 1), title = "Subplot 1")
p2 = scatter(rand(5, 1), title = "Subplot 2")
plot(p1, p2, layout = @layout([B C]), plot_title="Plot title", plot_titlevspan=0.5)