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!