How to merge two plots into one
조회 수: 28 (최근 30일)
이전 댓글 표시
I have the following data, related to the given script
% Plot profiles
load pressure_displacement_profiles
% Plot initial -Cp and shape
fig1=figure;
plot(initial.x,-initial.cp,'b-'); hold on;
a = plot(initial.x,initial.disp,'k-');
legend('cp','disp');
get(a)
% Plot optimal -Cp and shape
fig2=figure;
plot(optimal.x,-optimal.cp,'b-'); hold on;
b = plot(optimal.x,optimal.disp,'k-');
legend('cp','disp');
get(b);
% Save to eps
print(fig1,'-depsc2','Hwk1Prob3_starter1');
print(fig2,'-depsc2','Hwk1Prob3_starter2');
How do i show both Optimal and initial plot on the same graph?
댓글 수: 0
채택된 답변
Adam Danz
2019년 4월 24일
편집: Adam Danz
2019년 4월 24일
To put both axes on the same figure, use subplot()
% Plot initial -Cp and shape
fig1 = figure;
subplot(2,1,1)
plot(initial.x,-initial.cp,'b-');
hold on;
plot(initial.x,initial.disp,'k-');
legend('cp','disp');
% Plot optimal -Cp and shape
subplot(2,1,2)
plot(optimal.x,-optimal.cp,'b-');
hold on;
plot(optimal.x,optimal.disp,'k-');
legend('cp','disp');
% Save to eps
print(fig1,'-depsc2','Hwk1Prob3_starter1');
*Not tested
% Plot initial -Cp and shape
fig1 = figure;
p1 = plot(initial.x,-initial.cp,'b-');
hold on;
p2 = plot(initial.x,initial.disp,'k-');
% Plot optimal -Cp and shape
p3 = plot(optimal.x,-optimal.cp,'b-');
p4 = plot(optimal.x,optimal.disp,'k-');
legend([p1,p2,p3,p4], {'cp1','disp1','cp2','disp2'});
% Save to eps
print(fig1,'-depsc2','Hwk1Prob3_starter1');
*not tested
댓글 수: 6
Adam Danz
2019년 4월 30일
편집: Adam Danz
2019년 4월 30일
Some pointers
- get(p1) in your example lists all properties of the line, not the axes.
- to list properties of an axes, you need to get the axis handle. See the code below.
- "axHandle" is just the name I chose for the variable that stores the axis handle.
% Methods of getting axis handle
% 1) If and only if the axes are currently selected
axHandle = gca;
% 2) get the handle when you create the axes
figure
axHandle = axes;
% 3) get the handle from the line properties
h = plot(x,y);
axHandle = h.Parent;
And here's a description of all axes properties
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!