필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Sahil Wani
Sahil Wani 2024년 1월 28일
답변: Austin M. Weber 2024년 1월 28일
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.

채택된 답변

Austin M. Weber
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.

추가 답변 (1개)

Walter Roberson
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.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by