Clear Filters
Clear Filters

How can i make the legend as shown in the figure attached?

1 view (last 30 days)
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.

Accepted Answer

Austin M. Weber
Austin M. Weber on 28 Jan 2024
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.

More Answers (1)

Walter Roberson
Walter Roberson on 28 Jan 2024
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.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!