How to add a title to an existing plot?

Hi all!

I’m doing some plots for a series of data. Since I needed to multiply two columns, and plot the output in a box plot, I came up with this:


adc_I_symbol = Symbol("Arc ADC Current (A)")
adc_V_symbol = Symbol("Arc ADC Voltage (V)")

usb_variations = boxplot(0, title="Powers (V*I)")
@df df_normal boxplot!(cols(adc_I_symbol) .* cols(adc_V_symbol), label = "sub_r5_r4_255")
@df df_normal_0 boxplot!(cols(adc_I_symbol) .* cols(adc_V_symbol), label = "sub_r5_r4_0")
@df df_normal_31 boxplot!(cols(adc_I_symbol) .* cols(adc_V_symbol), label = "add_r5_r4_31")
@df df_USB boxplot!(cols(adc_I_symbol) .* cols(adc_V_symbol), label = "sub_r5_r4_255 (USB)")
@df df_USB_0 boxplot!(cols(adc_I_symbol) .* cols(adc_V_symbol), label = "sub_r5_r4_0 (USB)")
@df df_USB_31 boxplot!(cols(adc_I_symbol) .* cols(adc_V_symbol), label = "add_r5_r4_31 (USB)")

So, basically I first create an empty plot, then I populate it with the data. However, doing so won’t print the title. I can add it on the last call:

@df df_USB_31 boxplot!(cols(adc_I_symbol) .* cols(adc_V_symbol), label = "add_r5_r4_31 (USB)", title = "Powers (V*I)")

or on every call, but it clutters the code or make it slightly worse to maintain. Is there an idiomatic way to do this? I read that for example I can do that in Makie, but maybe I’m missing a simpler solution.

Thanks

The following works for me

julia> using StatsPlots

julia> plot(; title = "Test")

julia> boxplot!([1,2,3], label="a")

julia> boxplot!([1,2,3], label="a")
pkg> st StatsPlots Plots
Status `~/.julia/environments/plots1.0/Project.toml`
  [91a5bcdd] Plots v1.35.4
  [f3b207a7] StatsPlots v0.15.4
1 Like

It works, thanks! :confetti_ball: :tada:
For curiosity, what does the semicolon do? Does it separate mandatory and optional arguments?

This line should work too:
title!("My Title")

1 Like

That’s true, it works! :+1:

That is correct, I typed it out of habit, should also work without.

1 Like