How to set legend for a line segment?

3 visualizaciones (últimos 30 días)
Mr M.
Mr M. el 5 de Nov. de 2015
Editada: Thorsten el 10 de Nov. de 2015
How to add legend to this?: line([x1 x2],[y1,y2],'color','r','linestyle','--');

Respuestas (1)

Thorsten
Thorsten el 5 de Nov. de 2015
x1 = 10; x2 = 20; y1 = 12; y2 = 34;
line([x1 x2],[y1,y2],'color','r','linestyle','--');
legend('my dashed red line')
  2 comentarios
Mr M.
Mr M. el 9 de Nov. de 2015
Editada: Mr M. el 9 de Nov. de 2015
Yes, but I want to use it in general. For example I have plot; plot; line; plot; hist; line; plot; bars; etc. And how to add legend to the lines?
Thorsten
Thorsten el 10 de Nov. de 2015
Editada: Thorsten el 10 de Nov. de 2015
h = line([x1 x2],[y1,y2],'color','r','linestyle','--');
legend(h, 'my dashed red line')
If this does not the job, please post a minimal working example of what you try to do and what goes wrong.

Iniciar sesión para comentar.

Categorías

Más información sobre Legend en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by