将全局标题添加到 Plots.jl 子图(Adding global title to Plots.jl subplots)

``````using Plots
pyplot()
plot(rand(10,2), plot_title="Main title", title=["A" "B"], layout=2)
``````

``````# create a transparent scatter plot with an 'annotation' that will become title
y = ones(3)
title = Plots.scatter(y, marker=0,markeralpha=0, annotations=(2, y[2], Plots.text("This is title")),axis=false, grid=false, leg=false,size=(200,100))

# combine the 'title' plot with your real plots
Plots.plot(
title,
Plots.plot(rand(100,4), layout = 4),
layout=grid(2,1,heights=[0.1,0.9])
)
``````

``````using Plots
p1 = plot(sin, title = "sin")
p2 = plot(cos, title = "cos")
p = plot(p1, p2, top_margin=1cm)
import PyPlot
PyPlot.suptitle("Trigonometric functions")
PyPlot.savefig("suptile_test.png")
``````

`subplots``Plot`类型的字段，每个 subplot 都有一个名为`:attr`的字段，您可以修改和重新`display()`绘图。 请尝试以下操作：

``````julia> l = @layout([a{0.1h} ;b [c; d e]])
Plots.GridLayout(2,1)

julia> p = plot(randn(100,5),layout=l,t=[:line :histogram :scatter :steppre :bar],leg=false,ticks=nothing,border=false)

julia> p.subplots
5-element Array{Plots.Subplot,1}:
Subplot{1}
Subplot{2}
Subplot{3}
Subplot{4}
Subplot{5}

julia> fieldnames(p.subplots[1])
8-element Array{Symbol,1}:
:parent
:series_list
:bbox
:plotarea
:attr
:o
:plt

julia> for i in 1:length(p.subplots)
p.subplots[i].attr[:title] = "subtitle \$i"
end

julia> display(p)
``````

``````using Plots

layout = @layout [a{0.66w} b{0.33w}]
LHS = heatmap(rand(100, 100), title="Title for just the heatmap")
RHS = plot(1:100, 1:100, title="Only the line")
plot(LHS, RHS, plot_title="Overall title of the plot")
``````

``````p = plot(LHS, RHS)
p[:plot_title] = "Overall title of the plot"
plot(p)
``````