Plot Legend as 1 Row with 3 Variables?

10 visualizaciones (últimos 30 días)
Deborah Johnson
Deborah Johnson el 3 de Nov. de 2022
Comentada: Voss el 3 de Nov. de 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");

Respuesta aceptada

Voss
Voss el 3 de Nov. de 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 comentarios
Deborah Johnson
Deborah Johnson el 3 de Nov. de 2022
Thank you!
Voss
Voss el 3 de Nov. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by