Plot Legend as 1 Row with 3 Variables?
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Deborah Johnson
am 3 Nov. 2022
Kommentiert: Voss
am 3 Nov. 2022
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 Kommentare
Akzeptierte Antwort
Voss
am 3 Nov. 2022
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");
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!