Combine Plot and Scatter in Legend

23 次查看(过去 30 天)
Hello eveyone,
I have this graph :
In the legend I would like to display the curve and the scatter like that :
Tere is my code :
fig = figure;
set(fig, 'Units', 'Normalized', 'Position', [0.2 0.2 0.45 0.35]);
plot(B,A,"k",'LineStyle',':','linewidth',2)
hold on
s = scatter(B,A,35,'filled','diamond')
s.MarkerEdgeColor = "#BDD7EE";
s.MarkerFaceColor = "#D9D9D9";
plot(B,Abis,"k",'LineStyle','--','linewidth',1)
hold on
s2 = scatter(B,Abis,35,'filled','o')
s2.MarkerEdgeColor = "k";
s2.MarkerFaceColor = "#BDD7EE";
plot(B,MoyMatrice,"r",'LineStyle','-','linewidth',1)
hold on
scatter(B,MoyMatrice,35,'r','filled','o')
xlabel('Note subjective du broutement')
ylabel('Rating Occurence')
legend ('Run 1','Run 2','GLOBAL')
ylim ([0 maxx]) ;xlim([4 9]) %Fixer les limites d'axe
title (titre,'Interpreter','none')
ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'on';
ytickformat('percentage')
text(4.1,maxy-2,txt_Moyenne,'FontSize',14)
Thanks for considering !

采纳的回答

chicken vector
chicken vector 2023-4-25
x = 1:10;
y1 = randi(10,1,10);
y2 = randi(10,1,10);
y3 = randi(10,1,10);
figure;
hold on;
grid on;
plot(x,y1,':d',...
'LineWidth',2,...
'Color','k',...
'MarkerSize',10,...
'MarkerEdgeColor','#BDD7EE',...
'MarkerFaceColor','#D9D9D9')
plot(x,y2,'--o',...
'LineWidth',1,...
'Color','k',...
'MarkerSize',10,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','#BDD7EE')
plot(x,y3,'-o',...
'LineWidth',1,...
'Color','r',...
'MarkerSize',10,...
'MarkerEdgeColor','r',...
'MarkerFaceColor','r')
hold off;
legend('Curve 1','Curve 2','Curve 3','Location','NorthEastOutside');
Result:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by