legend for plot3 command

조회 수: 32 (최근 30일)
Indrajit Roy
Indrajit Roy 2020년 3월 18일
댓글: Adam Danz 2020년 3월 20일
I am going to plot two 3D data with the help of below command lines.
How can I insert legend for both the 3D data in a single window?
plot3(x,y,z);
hold on;
plot3(xx,yy,zz);

채택된 답변

Adam Danz
Adam Danz 2020년 3월 18일
Use the DisplayName property of graphics objects to specify the legend string.
plot3(x,y,z, 'DisplayName', 'Object1');
hold on;
plot3(xx,yy,zz, 'DisplayName', 'Object2');
legend()
or
p1 = plot3(x,y,z, 'DisplayName', 'Object1');
hold on;
p2 = plot3(xx,yy,zz, 'DisplayName', 'Object2');
legend([p1,p2])
  댓글 수: 4
Indrajit Roy
Indrajit Roy 2020년 3월 20일
편집: Indrajit Roy 2020년 3월 20일
Sorry for late reply...
  • If x,y,z vectors are of 2×2 dimension
  • and xx,yy,zz are of 1×2
then this error will appear:
''Error using horzcat
Dimensions of arrays being concatenated
are not consistent.''
I was pointing this issue.
Adam Danz
Adam Danz 2020년 3월 20일
I understood. My previous comment shows what to do under those circumstances.
Another alternative:
legend([p1(:);p2(:)])

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

추가 답변 (0개)

카테고리

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