Why can't I edit y label and x labels in matlab subplot figures (.FIG)

I have a 3 x 2 subplots (tiledlayout) with a common Y label and X label. I want to edit the labels and change the font and fontsize size but I'm unable to edit it.
The subplots axis labels were controlled by
tle = tiledlayout(3,2,"TileSpacing","compact");
tle.XLabel.String = 'Time';
tle.YLabel.String = 'Temp';
So its a single Y and X labels for the plots.this was done sometime ago and I need to edit the figs to change the fonts and fontsize. The problem does not affect figures with only one plot except for the subplots and tiledlayout figures.

 Accepted Answer

I’m not certain what the problem is.
You can get the handles to each subplot with:
Axsp = subplot(3,2,4); % Fourth Subplot Axes
for that particular subplot.
You then have access to that subplot’s properties:
Axsp.XLabel = 'NewLabel'
Axsp.XLabel.FontSize = 12;
Example —
figure
subplot(3,2,4)
plot((0:0.1:2*pi), sin((0:0.1:2*pi)))
xlabel('Time (s)')
ylabel('Velocity (cm/s)')
Then later —
Axsp = subplot(3,2,4); % Fourth Subplot Axes
Axsp.XLabel.FontSize = 12;
.

4 Comments

Dear Strider, thank you for your input. Unfortunately each plot does not have its own y and x axis label.
The subplots were controlled by
tle = tiledlayout(3,2,"TileSpacing","compact");
tle.XLabel.String = 'Time';
tle.YLabel.String = 'Temp';
So its a single Y and X labels for the plots.this was done sometime ago and I need to edit the figs to change the fonts and fontsize. The problem does not affect figures with only one plot except for the subplots and tiledlayout figures.
O.K. I thought ‘subplot’ meant subplot. They work as I described.
In tiledlayout plots, it is possible to give each tile its own axis labels, titles, and everything else. See Set Properties on the Axes for details. (Without specific information, I cannot provide specific solutions.) The only change you need is to assign specific handles to each axes object, as in that example. Then you can do essentially what I did in my subplot example.
EDIT — (121 Sep 2023 at 17:39)
figure
tle = tiledlayout(3,2,"TileSpacing","compact");
tle.XLabel.String = 'Time';
tle.YLabel.String = 'Temp';
x = linspace(0, 2*pi);
for k = 1:6
nexttile
plot(x, sin(k*x))
grid
end
sgtitle('Original')
savefig(gcf, 'Test.fig')
clear all
close all
F = openfig('Test.fig');
% Q = get(F)
TL = F.Children;
sgtitle(TL,'Original With Changes')
TL.XLabel.String = 'Time (\mus)';
TL.XLabel.FontSize = 16;
TL.XLabel.FontWeight = 'bold';
.

Sign in to comment.

More Answers (0)

Products

Release

R2023a

Community Treasure Hunt

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

Start Hunting!