# Super title in Plots and subplots

**URL:** <https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865>\
**Category:** General Usage\
**Tags:** plots, gr\
**Created:** [October 13, 2019, 3:42pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865 "2019-10-13T15:42:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliauser](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@juliauser](https://discourse.julialang.org/u/juliauser)\
**Post date:** [October 13, 2019, 3:42pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/1 "2019-10-13T15:42:24Z")

</div>

Hi,

I am having a hard time understanding how to organize titles in Plots.jl using pyplot().

I have 2X2 subplots and I would like to have a title for each subplot, one for each horizontal pair, and one for the overall plot. How can I do that?

Thanks

---

<div class="post-metadata">

**Author:** ![misha\_mikhasenko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/misha_mikhasenko/32/5060_2.png) [@misha\_mikhasenko](https://discourse.julialang.org/u/misha_mikhasenko)\
**Post date:** [October 13, 2019, 8:17pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/2 "2019-10-13T20:17:31Z")

</div>

Hi,

as you probably figured out, there is no problem of having a title per plot.  
It is set by a simple `title` option.

The others are not possible to add by `Plots.jl` options as far as I can tell.  
At least, you can always get a `matplotlib` object and act on it directly.

```julia
using Plots
pyplot()

plot(layout=grid(2,2))
plot!(x->x^2, -1, 2, sp=1, title="Title 1", frame=:box)
plot!(x->x^2, -1, 2, sp=2, title="Title 2", frame=:box)
plot!(x->x^2, -1, 2, sp=3, title="Title 3", frame=:box)
plot!(x->x^2, -1, 2, sp=4, title="Title 4", frame=:box)

plt = plot!()
fig = plt[3][1][:plot_object].o
children = fig[:get_children]()
ax = children[2]
ax[:text](0.6, 1.2, "My Big Title", fontsize=22, transform=ax[:transAxes], verticalalignment="bottom")
fig[:canvas][:print_figure]("awesome.pdf",bbox_inches="tight")

```

It feels ugly, I know.

---

<div class="post-metadata">

**Author:** ![juliauser](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@juliauser](https://discourse.julialang.org/u/juliauser)\
**Post date:** [October 22, 2019, 12:36pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/3 "2019-10-22T12:36:49Z")

</div>

Hi,

Thanks. Just to be clear, this code generates a title for the whole plot, but not for each row, right?

---

<div class="post-metadata">

**Author:** ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)\
**Post date:** [October 22, 2019, 1:08pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/4 "2019-10-22T13:08:42Z")

</div>

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:

```julia
using Plots
title = plot(title = "Plot title", grid = false, showaxis = false, bottom_margin = -50Plots.px)
p1 = scatter(rand(5, 1), title = "Subplot 1")
p2 = scatter(rand(5, 1), title = "Subplot 2")
plot(title, p1, p2, layout = @layout([A{0.01h}; [B C]]))

```

![title](https://global.discourse-cdn.com/julialang/original/3X/9/2/9215a51498b5195d0b7815066237469acf0c0173.png)

---

<div class="post-metadata">

**Author:** ![juliauser](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@juliauser](https://discourse.julialang.org/u/juliauser)\
**Post date:** [October 22, 2019, 1:36pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/5 "2019-10-22T13:36:14Z")

</div>

Thanks, this will do. Still surprised that Plots is missing very basic features.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [June 2, 2021, 1:16pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/6 "2021-06-02T13:16:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 2, 2021, 4:48pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/7 "2021-06-02T16:48:41Z")

</div>

@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:

```julia
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)

```

![Plots_gr_Supertitle](https://global.discourse-cdn.com/julialang/original/3X/9/9/9918a23ee89a05153028ec72259ad254194467c0.png)

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [June 2, 2021, 5:27pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/8 "2021-06-02T17:27:42Z")

</div>

Hi @rafael.guerra,

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.

---

<div class="post-metadata">

**Author:** ![Iddingsite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iddingsite/32/31840_2.png) [@Iddingsite](https://discourse.julialang.org/u/Iddingsite)\
**Post date:** [April 7, 2022, 12:00pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/9 "2022-04-07T12:00:57Z")

</div>

I am reviving this topic for a small update, as I came across this topic trying to solve the same problem, and this wasn’t the best solution:

There is now the plot\_title command, so you can do simply:

```julia
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")

```

which gives

![plot_5](https://global.discourse-cdn.com/julialang/original/3X/7/5/758ae162c2d5cbffcc5c4cf472c6a75551dfe520.png)

---

<div class="post-metadata">

**Author:** ![Marius\_123](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Marius\_123](https://discourse.julialang.org/u/Marius_123)\
**Post date:** [April 25, 2022, 8:29am UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/10 "2022-04-25T08:29:10Z")

</div>

How can you the control the position of the Plot title? Right now it is very close to the subplots.

---

<div class="post-metadata">

**Author:** ![Iddingsite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iddingsite/32/31840_2.png) [@Iddingsite](https://discourse.julialang.org/u/Iddingsite)\
**Post date:** [May 4, 2022, 6:43am UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/11 "2022-05-04T06:43:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![briederer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briederer/32/36201_2.png) [@briederer](https://discourse.julialang.org/u/briederer)\
**Post date:** [May 12, 2022, 12:10pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/12 "2022-05-12T12:10:08Z")

</div>

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:

```julia
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)

```

produces the following output:  
 ![out](https://global.discourse-cdn.com/julialang/original/3X/1/d/1dc09d32e0966f2f56c7ecddd5abdc3d4a10a907.png)

---

<div class="post-metadata">

**Author:** ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Post date:** [September 20, 2022, 5:43pm UTC](https://discourse.julialang.org/t/super-title-in-plots-and-subplots/29865/13 "2022-09-20T17:43:47Z")

</div>

In case anyone wants to display a supertitle for an array of plots using Makie.jl, here is [an example](https://docs.makie.org/v0.15/examples/layoutables/label/) in the Makie documentation.
