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);

 Respuesta aceptada

Adam Danz
Adam Danz el 18 de Mzo. de 2020

1 voto

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 comentarios

Indrajit Roy
Indrajit Roy el 18 de Mzo. de 2020
Thank you it's working now.
But, We've to take care vector dimension very carefully.Otherwise it'll show erros when concatenating.
Adam Danz
Adam Danz el 18 de Mzo. de 2020
Editada: Adam Danz el 18 de Mzo. de 2020
If p1 and p2 are not single objects, you can concatenate them vertically,
legend([p1;p2])
Or selection 1 element
legend([p1(1), p2(1)])
Is that what you're referring to?
Indrajit Roy
Indrajit Roy el 20 de Mzo. de 2020
Editada: Indrajit Roy el 20 de Mzo. de 2020
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 el 20 de Mzo. de 2020
I understood. My previous comment shows what to do under those circumstances.
Another alternative:
legend([p1(:);p2(:)])

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Etiquetas

Preguntada:

el 18 de Mzo. de 2020

Comentada:

el 20 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by