How can i make the legend as shown in the figure attached?
2 次查看(过去 30 天)
显示 更早的评论
I need to make the legend as shown in the figure as below:
I need to show markers for exp., solid line for Sim for same case as shown in figure.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1601956/image.jpeg)
0 个评论
采纳的回答
Austin M. Weber
2024-1-28
Generating some example data (use your actual data instead of this)
% Generating fake experimental data since I don't have yours
x_exp = linspace(0,12,20);
toyoura_exp = x_exp .^(1/3);
MH_exp = x_exp .^(1/3) .* 3;
CDH_exp = x_exp .^(1/3) .* 2;
% Generating fake simulation data since I don't have yours
x_sim = linspace(0,15,100);
toyoura_sim = x_sim .^(1/3);
MH_sim = x_sim .^(1/3) .* 3;
CDH_sim = x_sim .^(1/3) .* 2;
Plot the data:
figure
scatter(x_exp,toyoura_exp,'sk')
hold on
scatter(x_exp,MH_exp,'^r')
scatter(x_exp,CDH_exp,'ob')
plot(x_sim,toyoura_sim,'-k','LineWidth',1)
plot(x_sim,MH_sim,'-r','LineWidth',1)
plot(x_sim,CDH_sim,'-b','LineWidth',1)
hold off
Edit the appearance of the axes to match example figure
xlim([0,15]),ylim([0,10]), axis square, box on
ylabel('Deviator Stress {\itq} [MPa]')
xlabel('Axial Strain [%]')
set(gca,'XMinorTick','on','YMinorTick','on')
Create a legend with two columns:
legend_names = {'Toyoura sand (S_r^H=0.0%), Exp.,','MH (S_r^H=48.0%), Exp.,','CDH (S_r^H=49.0%), Exp.,',...
'Sim.','Sim.','Sim.'};
L=legend(legend_names);
L.NumColumns=2;
L.Location='north';
Add the additional text:
hold on
text(0.5,7,'Experiment: Miyazaki {\it et al.} (2016)')
text(10,0.5,'p_0^/ = 1.0 MPa')
hold off
Repeat the above steps for your second plot.
0 个评论
更多回答(1 个)
Walter Roberson
2024-1-28
The trick would be to configure two columns for the legend... and configure the legend entries for the first three legends to end in commas.
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!