The line on the legend are not showing

조회 수: 11 (최근 30일)
Romain
Romain 2024년 11월 29일
편집: Walter Roberson 2024년 11월 29일
When i try plotting a legend i end up with only the names of the curves. But when i change the type of line of my curves like if i put . or o, it is showing on my graph but not for a continuous line. i tried a few different way to put the legend, manually or just trusting matlab but it doesn't work.
Here's my code
a_1 = plot(X_1,Y_1, 'b-', 'DisplayName', "Onde incidente");
hold on ;
a_2 = plot(X_2, Y_2,'r-', 'DisplayName', "Onde transmise");
title("Signal experimental Mousse G");
legend show;
xlabel("temps (s)");
ylabel("amplitude");

채택된 답변

Walter Roberson
Walter Roberson 2024년 11월 29일
편집: Walter Roberson 2024년 11월 29일
What you describe sounds as if either X_1 or Y_1 are scalars. In such a case, requesting . or o will draw markers, but there would be no finite (x,y) pairs to draw lines between.
Lower probability is if X_1 or Y_1 happens to be such that it has infinite or nan entries between every finite entry.
x = 1:5;
y = [1 nan inf 4 nan];
subplot(2,1,1)
plot(x,y)
xlim([0 5]); ylim([0 5])
subplot(2,1,2)
plot(x,y,'o-')
xlim([0 5]); ylim([0 5])
The first plot does not show any lines because lines are only drawn if there are adjacent finite coordinates.

추가 답변 (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