필터 지우기
필터 지우기

How do I associate legend icons with the proper data?

조회 수: 3 (최근 30일)
Brad
Brad 2015년 1월 8일
답변: Brad 2015년 1월 8일
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?

채택된 답변

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by