Plot Legend as 1 Row with 3 Variables?
17 次查看(过去 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");
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!