How to combine a marker to a line and show in legend?

8 views (last 30 days)
f=figure(4);
set(f,'Color','w');
aa = gca;
line(Vs1,Depth1','Color','k','LineStyle','-','LineWidth',2)
hold on
line(Vs2,Depth2','Color','b','LineStyle','-','LineWidth',2)
hold on
line(Vs3,Depth3','Color','r','LineStyle','-','LineWidth',2)
hold on
line(Vs4,Depth4','Color','g','LineStyle','-','LineWidth',2)
hold on
line(Vs5,Depth5','Color','m','LineStyle','-','LineWidth',2)
hold on
scatter(Vs1,Depth1,50,'o','MarkerEdgeColor','k','MarkerFaceColor',["auto"]);
hold on
scatter(Vs2,Depth2,70,'s','MarkerEdgeColor','b','MarkerFaceColor',["auto"]);
hold on
scatter(Vs3,Depth3,70,'d','MarkerEdgeColor','r','MarkerFaceColor',["auto"]);
hold on
scatter(Vs4,Depth4,50,'^','MarkerEdgeColor','g','MarkerFaceColor',["auto"]);
hold on
scatter(Vs5,Depth5,50,'<','MarkerEdgeColor','m','MarkerFaceColor',["auto"]);
hold on
ax = gca;
ax.GridColor = ['k'];
ax.GridLineStyle = '--';
ax.GridAlpha = 0.5;
ax.Layer = 'bottom';
set(gca,'fontsize',15,'linewidth',1.5);
ylim([60 305]);
xlim([0 0.8]);
set(gca,'box','on', 'XGrid','of');
hold off
lgd=legend(['\fontsize{12}','U1244'],['\fontsize{12}','U1245'],['\fontsize{12}','U1247'],['\fontsize{12}','U1326'],['\fontsize{12}','U1327'],'location','southwest');
legend boxoff
set(lgd,'Location','best')

Accepted Answer

Star Strider
Star Strider on 13 Aug 2022
Insteaqd of using separate line and scatter calls, use plot. Specifically, see LineSpec.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!