Filter löschen
Filter löschen

How do I associate legend icons with the proper data?

7 Ansichten (letzte 30 Tage)
Brad
Brad am 8 Jan. 2015
Beantwortet: Brad am 8 Jan. 2015
I’m generating a plot containing 2 sets of data (data set 1 & data set 2)) using the following code;
h = plot(Pre_TALO_Time1, Pre_Altitude1, '-o', Post_TALO_Time1, Post_Altitude1, '-d', Pre_TALO_Time2, Pre_Altitude2, '-o', Post_TALO_Time2, Post_Altitude2, '-d', 'MarkerSize', 15);
set(h(1), 'Color', 'r', 'MarkerFaceColor', 'r');
set(h(2), 'Color', 'r', 'MarkerFaceColor', 'r');
set(h(3), 'Color', 'b', 'MarkerFaceColor', 'b');
set(h(4), 'Color', 'b', 'MarkerFaceColor', 'b');
% Hold all current axes and connect the data sets
hold on;
xx = [Pre_TALO_Time1(end), Post_TALO_Time1(1)];
yy = [Pre_Altitude1(end), Post_Altitude1(1)];
plot(xx, yy, 'r-', 'LineWidth', 1);
hold on;
aa = [Pre_TALO_Time2(end), Post_TALO_Time2(1)];
bb = [Pre_Altitude2(end), Post_Altitude2(1)];
plot(aa, bb, 'b-', 'LineWidth', 1);
% Add the title, legend, and classification
title(Event_Title, 'Fontsize', 20, 'fontweight', 'b');
legend(Source1, Source2, 'Location', 'NortheastOutside');
set(legend, 'FontSize', 20);
Max_TALO_X_Values = [max(Pre_TALO_Time1) max(BO_TALO_Time1) max(Post_TALO_Time1) max(Pre_TALO_Time2) max(BO_TALO_Time2) max(Post_TALO_Time2)];
Max_TALO_X = max(Max_TALO_X_Values);
set(gca, 'XLim', [0 10*ceil(max(Max_TALO_X)/10)]);
Max_Y_Values = [max(Pre_Altitude1) max(BO_Altitude1) max(Post_Altitude1) max(Pre_Altitude2) max(BO_Altitude2) max(Post_Altitude2)];
Max_Y = max(Max_Y_Values);
set(gca, 'YLim', [0 10*ceil(max(Max_Y)/10)]);
set(gca, 'Fontsize', 16);
grid on;
box on;
The resulting plot is this;
The legend contains the correct icon proceeding 'data1'. However, the diamond icon proceeding 'data2' is not correct. It should be a blue circle with a line through it.
What could be causing this?

Akzeptierte Antwort

Brad
Brad am 8 Jan. 2015
Replaced the original legend function parameters with the following;
legend([h(1) h(3)],{Source1, Source2}, 'Location', 'NortheastOutside' );
Legend is now appearing as desired.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by