how to include symbol on plot line into the legend?
28 ビュー (過去 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!