Creating text for subcaptions in subplot figure
8 views (last 30 days)
Show older comments
Hello,
I want to use a subplot in a journal that doesn't allow multiple figures (so I need to pre-combine them). So I thought in using subplot which should be easy to create a figure with 4 different plots. The plot script is below.
clc;clear;
rng(4); % for always having same results
data1_x = sort(randi(10,1,5));
data2_x = sort(randi(10,1,5));
data3_x = sort(randi(10,1,5));
data4_x = sort(randi(10,1,5));
data1_y = sort(randi([10,30],1,5));
data2_y = sort(randi([10,30],1,5));
data3_y = sort(randi([10,30],1,5));
data4_y = sort(randi([10,30],1,5));
figure()
subplot(2,2,1)
plot(data1_x, data1_y)
legend()
subplot(2,2,2)
plot(data2_x, data2_y)
subplot(2,2,3)
plot(data3_x, data3_y)
subplot(2,2,4)
plot(data1_x, data4_y)
This generates the following plot:

And I want something as the following (but with a precise placement instead of a paint like I did now). I know I can accomplish this through annotation, but well annotation is a very unreliable function in my opinion (i.e it changes if you change the size of your picture by maximizing/restoring down).

0 Comments
Answers (1)
Rik
on 4 Jun 2020
Edited: Rik
on 4 Jun 2020
Even for subplots you can use the title and xlabel functions. Your picture looks like you want to use xlabel.
clc;clear;
rng(4); % for always having same results
data1_x = sort(randi(10,1,5));
data2_x = sort(randi(10,1,5));
data3_x = sort(randi(10,1,5));
data4_x = sort(randi(10,1,5));
data1_y = sort(randi([10,30],1,5));
data2_y = sort(randi([10,30],1,5));
data3_y = sort(randi([10,30],1,5));
data4_y = sort(randi([10,30],1,5));
figure(1),clf(1)
subplot(2,2,1)
plot(data1_x, data1_y)
xlabel('(a)')
subplot(2,2,2)
plot(data2_x, data2_y)
xlabel('(b)')
subplot(2,2,3)
plot(data3_x, data3_y)
xlabel('(c)')
subplot(2,2,4)
plot(data1_x, data4_y)
xlabel('(d)')
0 Comments
See Also
Categories
Find more on Subplots 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!