How to make subplots bigger and title in one line?

10 次查看(过去 30 天)
Hi all, I would like to make my subplots larger so that all four fill my window (quarter the window, so to speak)
Furthermore I would like to have the subplot title in one line and not a line break at each title where I write my initial values.
Any help is appreciated!
%plotting
fig1 = figure();
fig1.WindowState = 'maximized';
subplot(4,2,1)
plot(elapsedTime, volt/1000, 'b')
hold on
for i = 1:length(time)
if boole(i) == 1
line ("xdata",[elapsedTime(i),elapsedTime(i)], "ydata",[max(volt/1000)/1.5,max(volt/1000)], "linewidth", 0.5, 'linestyle', '--')
text(elapsedTime(i), max(volt/1000), [num2str(volt(i)/1000) "V"], 'HorizontalAlignment', 'left', 'VerticalAlignment', 'top', 'FontSize', 14);
end
end
title(["Battery Voltage over Time (Initial RSoC = " num2str(rsoc(1)) "%)"])
xlabel("Time in s")
ylabel("Battery Voltage in V")
xlim([0 elapsedTime(end)])
ax(1)=gca;
grid on
zoom on
subplot(4,2,2)
plot(elapsedTime, curr/1000, 'r')
hold on
for i = 1:length(time)
if boole(i) == 1
line ("xdata",[elapsedTime(i),elapsedTime(i)], "ydata",[min(curr/1000),max(curr/1000)], "linewidth", 0.5, 'linestyle', '--')
end
end
title(["Battery Current over Time (Integrated Capacity Q = " num2str(round(100*Q)/100) "Ah)"])
xlabel("Time in s")
ylabel("Battery Current in A")
xlim([0 elapsedTime(end)])
ax(2)=gca;
grid on
zoom xon
subplot(4,2,3)
plot(elapsedTime, temp, 'k')
title(["Battery Temperature over Time (Initial Battery Temperature = " num2str(temp(1)) "°C)"])
xlabel("Time in s")
ylabel("Battery Temperature in °C")
xlim([0 elapsedTime(end)])
ax(3) = gca;
grid on
zoom xon
subplot(4,2,4)
plot(elapsedTime, rsoc)
hold on
for i = 1:length(time)
if boole(i) == 1
line ("xdata",[elapsedTime(i),elapsedTime(i)], "ydata",[0,max(rsoc)+10], "linewidth", 0.5, 'linestyle', '--')
text(elapsedTime(i), max(rsoc-10), [num2str(rsoc(i)) "%" ], 'HorizontalAlignment', 'left', 'VerticalAlignment', 'top', 'FontSize', 14);
end
end
title([" Relative State of Charge over Time (Initial RSoC = " num2str(rsoc(1)) "%)"])
xlabel("Time in s")
ylabel("State of Charge in %")
ylim([0 100]);
xlim([0 elapsedTime(end)])
ax(4)=gca;
grid on
zoom xon
linkaxes(ax, 'x')

采纳的回答

Dyuman Joshi
Dyuman Joshi 2024-2-8
编辑:Dyuman Joshi 2024-2-8
Using tiledlayout here seems to be a better option, as it gives you a better control over the spacing and padding.
Also, while concatenating with a string array, use +. When you simply place a numerical value in between strings, the value will be convert to a string scalar and the result will be a string array, which when provided as input to title() displays each element in a separate line -
x1 = ["String" 55 "Yo"]
x1 = 1x3 string array
"String" "55" "Yo"
x2 = "String " + 55 + " Yo"
x2 = "String 55 Yo"
tiledlayout(2, 2, 'TileSpacing', 'compact')
[X,Y,Z] = peaks(20);
% Tile 1
nexttile
surf(X,Y,Z)
title("Battery Voltage " + 55 + " %")
% Tile 2
nexttile
contour(X,Y,Z)
title("Battery Current " + 65 + "Ah")
% Tile 3
nexttile
imagesc(Z)
title("Battery Temperature " + 42.0 + "°C")
% Tile 4
nexttile
plot3(X,Y,Z)
title("Relative State of Charge " + randi(100) + "%")

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by