How to fully display y-axis labels if they do not fit inside of the figure window when specifying a figure size and using subsubplot?
Ältere Kommentare anzeigen
I am using the subsubplot function from the Climate Data Toolbox to make a figure that is 3 inches wide by 4 inches tall, but the y-axis labels are only partially displayed within the figure box. Here is an example (I am using R2022a):
% Create data
xdata = (0:18:180)';
ydata1 = randi(40,size(xdata));
ydata2 = randi(90,size(xdata));
ydata3 = randi(35,size(xdata));
ydata = [ydata1,ydata2,ydata3];
% Y-axis label names
ydata_label = {'Sample 1','Sample 2','Sample 3'};
ydata_units = {'(%)','(%)','(%)'};
% Plot figure
figure('units','inches','position',[1,1,3,4])
numRows = size(ydata,2);
for i = 1:numRows
subsubplot(numRows,1,i)
plot(xdata,ydata(:,i))
xlabel('Measurement')
ylabel({ydata_label{i};ydata_units{i}})
if mod(i,2) == 0 % i.e., when 'i' is an even number
set(gca,'YAxisLocation','right')
end
set(gca,'FontName','Calibri Light','FontSize',10,'TickDir','out')
end
The above code will result in something like this:

I can stretch the figure horizontally and the labels will eventually display correctly, but the figure no longer has the desired size:

How can I resize the axes within the figure window so that the y-axis labels are visible while maintaining a 3 inch by 4 inch figure size?.
2 Kommentare
Dyuman Joshi
am 3 Okt. 2023
Replace subsubplot() command with subplot() and check if that works for you or not.
Austin M. Weber
am 3 Okt. 2023
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Calendar finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!