Does anyone know if its possible to make a series plot that includes only one label for the whole series (instead of an array of labels that get displayed on the legend).
For example, say I had some experimental trial data as follows:
using GLMakie
trial_1 = [1, 5, 3]
trial_2 = [2, 9, 1]
trial_3 = [4, 2, 7]
trials = [trial_1 trial_2 trial_3]
Now I want to plot the mean of these trials as well as the separate trials as follows:
fig, ax = series(trials, solid_color=(:red, 0.3))
lines!(ax, vec(mean(trials, dims=1)), color=:red, label="mean")
axislegend(ax)
fig
The legend currently displays, “series 1”, “series 2”, and “series 3”. Ideally, I’d want this to display just one label named “trials” (so there would only be two legend entries: “trials” and “mean”).
Any help is appreciated. Thanks.
Have you tried the merge
keyword as described in the docs (Legend · Makie)?
1 Like
Yeah cheers, I did know about the merge keyword, but my problem was that I couldn’t input a single label for all the series plots.
But now using merge at least I can input an array of the same labels and it will work as I want:
fig, ax = series(trials, solid_color=(:red, 0.3), labels=repeat(["trials"], 5))
lines!(ax, vec(mean(trials, dims=1)), color=:red, label="mean", linewidth=4)
axislegend(ax, merge=true)
fig
1 Like
use Legend
using GLMakie, Statistics
trial_1 = [1, 5, 3]
trial_2 = [2, 9, 1]
trial_3 = [4, 2, 7]
trials = [trial_1 trial_2 trial_3]
colors = [:blue, :red]
function plot_res()
fig = Figure()
ax = Axis(fig[1, 1])
series!(ax, trials, solid_color=colors[1])
lines!(ax, vec(mean(trials, dims=1)), color=colors[2], label="mean")
elems = [PolyElement(color=c, strokecolor=:blue, strokewidth=1) for c in colors]
Legend(fig[1, 2], elems, ["Trials", "Mean"])
fig
end
plot_res()