Plots -> PgfPlotsX: Group plot only "outer edge" x and y-labels?

Hello!

I am using Plots with pgfplotsx(). I have made a plot which looks like:

Marked in yellow is the labels I would like to remove. I understand that one way to avoid these labels is by not constructing them in the first place, but I also save the plots individually, so I would just like to specify that for the group plot do not put the “inner” labels but only the outer ones, which are not marked in yellow.

Sample code to do this based on Layouts · Plots

using Plots
pgfplotsx()

plot(rand(100,4), layout = 4, label=["a" "b" "c" "d"],
    title=["1" "2" "3" "4"])
xlabel!("hi")
ylabel!("bye")

Kind regards

You can either modify the axis labels of subplots

p = plot(
    rand(100, 4),
    layout = 4,
    label = ["a" "b" "c" "d"],
    title = ["1" "2" "3" "4"],
)
xlabel!(p[3], "hi")
xlabel!(p[4], "hi")
ylabel!(p[1], "bye")
ylabel!(p[3], "bye")

or specify them for each subplot in the plot command by passing row vectors.

p = plot(
    rand(100, 4),
    layout = 4,
    label = ["a" "b" "c" "d"],
    title = ["1" "2" "3" "4"],
    xlabel = ["" "" "hi" "hi"],
    ylabel = ["bye" "" "bye" ""],
)

Both result in this plot:

This is a step in the right direction! Suppose I have an array defined as:

all_plots
4-element Array{Plots.Plot,1}:
 Plot{Plots.PGFPlotsXBackend() n=5}
 Plot{Plots.PGFPlotsXBackend() n=5}
 Plot{Plots.PGFPlotsXBackend() n=5}
 Plot{Plots.PGFPlotsXBackend() n=5}

So basically p[1], p[2] etc. How would I then select only odd/even indices, so that I could write;

xlabel!(all_plots[even_indices]," ")

EDIT: one simple solution I found is:

ylabel!.(all_plots[2:2:4],"")

Kind regards

If I had an array all_plots of plots and I wanted to combine them as subplots in a layout, I would do it like this:

all_plots = [plot(rand(100)) for i in 1:4]

plot(
    all_plots..., 
    xlabel = ["" "" "hi" "hi"],
    ylabel = ["bye" "" "bye" ""],
)

For general layout grid sizes:

m = 5
n = 3
all_plots = [plot(rand(100)) for i in 1:m*n]

plot(
    all_plots...,
    layout = (m, n),
    xlabel = permutedims([i > (m - 1) * n ? "hi" : "" for i in 1:m*n]),
    ylabel = permutedims([mod(i, n) == 1 ? "bye" : "" for i in 1:m*n]),
)
1 Like

Awesome, I like how compact it is!

I will look into it if my situation becomes more complex.

Kind regards