Check if plot title already exists before adding again

This commit is contained in:
Pearl Li 2022-01-10 15:52:43 -08:00
parent 1014b8f494
commit b30286b1db

View File

@ -277,17 +277,17 @@ end
function _add_plot_title!(plt) function _add_plot_title!(plt)
plot_title = plt[:plot_title] plot_title = plt[:plot_title]
if plot_title != "" if plot_title != ""
# make new subplot for plot title
if plt[:plot_titleindex] == 0
the_layout = plt.layout the_layout = plt.layout
vspan = plt[:plot_titlevspan] vspan = plt[:plot_titlevspan]
plt.layout = grid(2, 1, heights = (vspan, 1 - vspan)) plt.layout = grid(2, 1, heights = (vspan, 1 - vspan))
plt.layout.grid[1, 1] = subplot = Subplot(plt.backend, parent = plt.layout[1, 1]) plt.layout.grid[1, 1] = subplot = Subplot(plt.backend, parent = plt.layout[1, 1])
plt.layout.grid[2, 1] = the_layout plt.layout.grid[2, 1] = the_layout
subplot.plt = plt subplot.plt = plt
# propagate arguments plt[:plot_titleXXX] --> subplot[:titleXXX]
for sym in filter(x -> startswith(string(x), "plot_title"), keys(_plot_defaults))
subplot[Symbol(string(sym)[(length("plot_") + 1):end])] = plt[sym]
end
top = plt.backend isa PyPlotBackend ? nothing : 0mm top = plt.backend isa PyPlotBackend ? nothing : 0mm
bot = 0mm bot = 0mm
plt[:force_minpad] = nothing, top, nothing, bot plt[:force_minpad] = nothing, top, nothing, bot
@ -297,6 +297,15 @@ function _add_plot_title!(plt)
subplot[:margin] = 0px subplot[:margin] = 0px
push!(plt.subplots, subplot) push!(plt.subplots, subplot)
end end
# propagate arguments plt[:plot_titleXXX] --> subplot[:titleXXX]
plot_titleindex = plt[:plot_titleindex]
subplot = plt.subplots[plot_titleindex]
for sym in filter(x -> startswith(string(x), "plot_title"), keys(_plot_defaults))
subplot[Symbol(string(sym)[(length("plot_") + 1):end])] = plt[sym]
end
end
return nothing return nothing
end end