Plot Legend as 1 Row with 3 Variables?

16 次查看(过去 30 天)
Hello,
Is the a way to call up a Legend as >> legend.NumRows = 1? I am told this is not a valid property but there is NumColumns?
I have 3 variables with one plot and the legend's location is 'southoutside'. It is using up valuable footprint area with tiledlayout - figure export graphics.
Thank you.
nexttile
plot(data1.Simulation_Time, data1.OP_Speed_Cmd, data1.Simulation_Time, data1.AFS_Speed_Cmd, "k--",...
data1.Simulation_Time, data1.Airspeed, "r-");
hold on
ax = gca; % Get handle to current axes.
ax.GridAlpha = 0.5; % Make grid lines less transparent.
grid On;
ax.XAxis.TickValues = 0:250:1500;
ylim([15 65]);
xlabel("Simulation Time (sec)", 'FontSize', 9);
ylabel("Knots", 'FontSize', 9);
legend({"Oper Speed Cmd", "AFS Speed Cmd", "Air Speed"}, 'Location', 'southoutside', 'FontSize', 7, 'LineWidth', 1);
title("PR I0148A 3a: Aircraft Speed");

采纳的回答

Voss
Voss 2022-11-3
Set NumColumns equal to the number of lines, in this case 3.
% random data
data1 = struct( ...
'Simulation_Time',0:100:1400, ...
'OP_Speed_Cmd',15+50*rand(1,15), ...
'AFS_Speed_Cmd',15+50*rand(1,15), ...
'Airspeed',15+50*rand(1,15));
nexttile
plot(data1.Simulation_Time, data1.OP_Speed_Cmd, data1.Simulation_Time, data1.AFS_Speed_Cmd, "k--",...
data1.Simulation_Time, data1.Airspeed, "r-");
hold on
ax = gca; % Get handle to current axes.
ax.GridAlpha = 0.5; % Make grid lines less transparent.
grid On;
ax.XAxis.TickValues = 0:250:1500;
ylim([15 65]);
xlabel("Simulation Time (sec)", 'FontSize', 9);
ylabel("Knots", 'FontSize', 9);
legend({"Oper Speed Cmd", "AFS Speed Cmd", "Air Speed"}, ...
'Location', 'southoutside', ...
'FontSize', 7, ...
'LineWidth', 1, ...
'NumColumns', 3);
title("PR I0148A 3a: Aircraft Speed");

更多回答(0 个)

类别

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

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by