how to include symbol on plot line into the legend?
조회 수: 38 (최근 30일)
이전 댓글 표시
To make my plots clear in greyscale, I'm using symbols and I want these to appear on the legend as well as the line colour. Does anyone know how to do this?
plot(IPA5a(end-1000:end,1)*10^-6, IPA5a(end-1000:end,3)*10^9,'Color','g','LineWidth',1)
hold on
plot(IPA5a(end-1000:20:end,1)*10^-6, IPA5a(end-1000:20:end,3)*10^9,'<','Color','g')
legend({'IPA'},'Location','southeast')
댓글 수: 0
답변 (2개)
C B
2023년 8월 16일
Is this what you are looking for using this symbol '<' ?
n = 2000;
IPA5a = [linspace(0, 2*pi, n)' sin(linspace(0, 2*pi, n))'];
% Plotting the continuous line
p1 = plot(IPA5a(end-1000:end,1)*10^-6, IPA5a(end-1000:end,2)*10^9, ...
'Color','k', 'LineWidth',1, 'LineStyle','-'); % 'k' for black
hold on
% Overlaying the markers
p2 = plot(IPA5a(end-1000:20:end,1)*10^-6, IPA5a(end-1000:20:end,2)*10^9, ...
'<', 'Color','k', 'MarkerFaceColor','k');
% Adding the legend to reflect both line and marker
legend([p1, p2], {'IPA Line', 'IPA Marker'}, 'Location', 'southeast');
hold off
댓글 수: 0
Star Strider
2023년 8월 16일
The code plots two lines, however has only one legend entry, so the second series (with the '<' marker) does not show up in the legend. Use '<g' to plot the markers, or '<-g' to plot the markers with a line linking them. That aside, both lines are the same colours, so that may make them a bit difficult to distinguish.
IPA5a = rand(2000,3)+[0 1 2]+1E10;
IPA5a(:,1) = sort(IPA5a(:,1));
figure
plot(IPA5a(end-1000:end,1)*10^-6, IPA5a(end-1000:end,3)*10^9,'Color','g','LineWidth',1)
hold on
plot(IPA5a(end-1000:20:end,1)*10^-6, IPA5a(end-1000:20:end,3)*10^9,'<g')
legend({'IPA','IPA<'},'Location','southeast')
.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!