Axis labels for subplot figure

94 views (last 30 days)
Eric Escoto
Eric Escoto on 29 Aug 2019
Edited: Cris LaPierre on 30 Aug 2019
Hi All,
I'm trying to place an x and y-axis label onto the figure centered horizonally (for x axis) and vertically (for y axis).
I've found a resaonable way to make the title using 'sgtitle' but nothing seems to exist for the lables, which is odd. How could I do this?
The current lines I have are copied below. I've commented out each of the subplot labels as I only need one for the entire figure.
Thanks!
%% Create a figure 2 x 6 (representing 12 months).
figure
sgtitle('January', 'FontSize', 15)
subplot(6, 2, 1)
title('January', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.
subplot(6, 2, 2)
scatter(drophist_SFL2019_feb(:,1), drophist_SFL2019_feb(:,2), 'filled')
title('February', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.
subplot(6, 2, 3)
scatter(drophist_SFL2019_mar(:,1), drophist_SFL2019_mar(:,2), 'filled')
title('March', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.
subplot(6, 2, 4)
scatter(drophist_SFL2019_apr(:,1), drophist_SFL2019_apr(:,2), 'filled')
title('April', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.
subplot(6, 2, 5)
scatter(drophist_SFL2019_may(:,1), drophist_SFL2019_may(:,2), 'filled')
title('May', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.
subplot(6, 2, 6)
scatter(drophist_SFL2019_jun(:,1), drophist_SFL2019_jun(:,2), 'filled')
title('June', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.
subplot(6, 2, 7)
scatter(drophist_SFL2019_jul(:,1), drophist_SFL2019_jul(:,2), 'filled')
title('July', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.
subplot(6, 2, 8)
scatter(drophist_SFL2019_aug(:,1), drophist_SFL2019_aug(:,2), 'filled')
title('August', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.
subplot(6, 2, 9)
title('September', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.
subplot(6, 2, 10)
title('October', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.
subplot(6, 2, 11)
title('Novemeber', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.
subplot(6, 2, 12)
title('December', 'FontSize', 15)
%xlabel('Size [mm]', 'FontSize', 15)
%ylabel('Speed [m/s]', 'FontSize', 15)
xlim([0 11])
ylim([0 11])
xticks([0 1.25 2.5 5.0 8.0 10.0 20.0 26.0]) % These ticks delineate changes in class spread.
yticks([0 1.0 2.0 4.0 8.0 11.0 16.0 22.4]) % These ticks delineate changes in class spread.
hold on
plot(X, vD_AfGK, 'k', 'LineWidth', 2) % This plots the Atlas empirical v(D) line from Gunn-Kinzer's data.
plot(X, vD_AU, 'k', 'Linewidth', 2, 'LineStyle', '--') % This plots the Atlas and Ulbrich v(D) line.
plot(X, vD_VD, 'k', 'Linewidth', 2, 'LineStyle', ':') % This plots the van Dijk et. al. v(D) line.

Answers (1)

Cris LaPierre
Cris LaPierre on 30 Aug 2019
Does the solution given here work for you?
  2 Comments
Eric Escoto
Eric Escoto on 30 Aug 2019
Hi Cris,
I've found this question prior to asking my own. I'm not really sure what it is doing. Perhaps you could expand on what this answer is doing?
I can add six more subplots to the script you linked but need help figuring it all out to test it.
-Eric
Cris LaPierre
Cris LaPierre on 30 Aug 2019
Edited: Cris LaPierre on 30 Aug 2019
It uses the position of the existing plots to calculate the size (height and width) of a rectangle encompassing all plots in the window. It then uses the positions to place a new hidden axes over all the plots and adds a new x and y label to that axes.
You can see more details on what position is here.
In subplots, plots are filled in left to right, top to bottom. For the 2x2 example in the linked post, it would look like this
1 2
3 4
Height is the difference between the top position of the first row - the bottom postion of the bottom row. Using the information provided in position, this is p1(2) + p1(4) - p4(2).
  • p1 could be any plot in the first row
  • p4 could be any plot in the bottom row
Width is the difference between the right position of the last column - the left position of the first column. Using the information provided in position, this is p4(1) + p4(3) - p3(1).
  • p4 could be any plot in the last column
  • p3 could be any plot in the first column
With this info, you can now place the new hidden axes. Position is [left_edge bottom_edge width height]. P3 is used because it is the bottom left plot.
When adding the labels, you could do
axes(h5)
ylabel('test')
xlabel('test')
or
ylabel(h5,'test')
xlabel(h5,'test')
You really only need the position of 3 of the subplots
  1. Top left
  2. Bottom left
  3. Bottom right
You are plotting 6x2, so plots 1, 11 and 12.

Sign in to comment.

Categories

Find more on Axes Appearance in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!