how to include symbol on plot line into the legend?
28 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
C B
il 16 Ago 2023
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 Commenti
Star Strider
il 16 Ago 2023
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 Commenti
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!