The line on the legend are not showing

7 次查看(过去 30 天)
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