Plotting multiple 3D plots on one graph

조회 수: 18 (최근 30일)
JD
JD 2019년 10월 2일
편집: JD 2019년 10월 3일
Hi,
I have the following code. I want to plot all 7 on the same plot. How do I do that?
I tried hold on, but that gives me an empty plot. Thank you!
figure (4)
plot3(cm_willans,pma_1400,pme_e, '-r');
plot3(cm_willans,pma_1900,pme_e, '-m');
plot3(cm_willans,pma_2500,pme_e, '-g');
plot3(cm_willans,pma_3000,pme_e, '-b');
plot3(cm_willans,pma_4200,pme_e, '-k');
plot3(cm_willans,pma_5300,pme_e, '-y');
plot3(cm_willans,pma_6400,pme_e, '-c');
grid on
hold on
xlabel('Cm in m/s')
ylabel('Pma in Pascals')
zlabel('Pme in Pascals')
Also, secondary question: How do I create a legend for each one of those lines? Thanks

채택된 답변

Shubham Gupta
Shubham Gupta 2019년 10월 2일
Try :
figure (4)
grid on
hold on % Hold position should be at the start of plotting to overlap plots
plot3(cm_willans,pma_1400,pme_e, '-r','DisplayName','legend-1');
plot3(cm_willans,pma_1900,pme_e, '-m','DisplayName','legend-2');
plot3(cm_willans,pma_2500,pme_e, '-g','DisplayName','legend-3');
plot3(cm_willans,pma_3000,pme_e, '-b','DisplayName','legend-4');
plot3(cm_willans,pma_4200,pme_e, '-k','DisplayName','legend-5');
plot3(cm_willans,pma_5300,pme_e, '-y','DisplayName','legend-6');
plot3(cm_willans,pma_6400,pme_e, '-c','DisplayName','legend-7'); % DisplayName property to set legend name
xlabel('Cm in m/s')
ylabel('Pma in Pascals')
zlabel('Pme in Pascals')
legend show
Hope it helps !
  댓글 수: 5
Shubham Gupta
Shubham Gupta 2019년 10월 3일
편집: Shubham Gupta 2019년 10월 3일
Use subplot to create subplots on the plot. Try :
figure;
subplot(171)
plot3(cm_willans,pma_1400,pme_e, '-r','DisplayName','legend-1');
xlabel('Cm in m/s')
ylabel('Pma in Pascals')
zlabel('Pme in Pascals')
legend show
subplot(172)
plot3(cm_willans,pma_1900,pme_e, '-m','DisplayName','legend-2');
xlabel('Cm in m/s')
ylabel('Pma in Pascals')
zlabel('Pme in Pascals')
legend show
subplot(173)
plot3(cm_willans,pma_2500,pme_e, '-g','DisplayName','legend-3');
xlabel('Cm in m/s')
ylabel('Pma in Pascals')
zlabel('Pme in Pascals')
legend show
subplot(174)
plot3(cm_willans,pma_3000,pme_e, '-b','DisplayName','legend-4');
xlabel('Cm in m/s')
ylabel('Pma in Pascals')
zlabel('Pme in Pascals')
legend show
subplot(175)
plot3(cm_willans,pma_4200,pme_e, '-k','DisplayName','legend-5');
xlabel('Cm in m/s')
ylabel('Pma in Pascals')
zlabel('Pme in Pascals')
legend show
subplot(176)
plot3(cm_willans,pma_5300,pme_e, '-y','DisplayName','legend-6');
xlabel('Cm in m/s')
ylabel('Pma in Pascals')
zlabel('Pme in Pascals')
legend show
subplot(177)
plot3(cm_willans,pma_6400,pme_e, '-c','DisplayName','legend-7');
xlabel('Cm in m/s')
ylabel('Pma in Pascals')
zlabel('Pme in Pascals')
legend show
I am not sure if that's what you want. Let me know if you have doubts
JD
JD 2019년 10월 3일
Thank you Shubham

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

OMKAR SHETYE
OMKAR SHETYE 2021년 8월 28일
For the legend part :- first create a vector which will have all the names for the respective plots, then call the legend function using the pre-defined vector.
figure (4)
grid on
hold on % Hold position should be at the start of plotting to overlap plots
plot3(cm_willans,pma_1400,pme_e, '-r','DisplayName','legend-1');
plot3(cm_willans,pma_1900,pme_e, '-m','DisplayName','legend-2');
plot3(cm_willans,pma_2500,pme_e, '-g','DisplayName','legend-3');
plot3(cm_willans,pma_3000,pme_e, '-b','DisplayName','legend-4');
plot3(cm_willans,pma_4200,pme_e, '-k','DisplayName','legend-5');
plot3(cm_willans,pma_5300,pme_e, '-y','DisplayName','legend-6');
plot3(cm_willans,pma_6400,pme_e, '-c','DisplayName','legend-7'); % DisplayName property to set legend name
xlabel('Cm in m/s')
ylabel('Pma in Pascals')
zlabel('Pme in Pascals')
v = ["Plot-1","Plot-2","Plot-3","Plot-4","Plot-5","Plot-6","Plot-7"]
legend(v)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by