How can i make the legend as shown in the figure attached?
조회 수: 1 (최근 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!