Unable to add title to legend

5 visualizaciones (últimos 30 días)
Ayush Mishra
Ayush Mishra el 22 de Sept. de 2016
Editada: Walter Roberson el 23 de Sept. de 2016
I tried to give a title to the legend on my plot but the error of Error using title (line 27) Incorrect number of input arguments
So I tried using the example given on the Matlab website:
x = -pi:pi/20:pi;
y1 = sin(x);
plot(x,y1)
hold on
y2 = cos(x);
plot(x,y2)
hold off
lgd = legend('sin(x)','cos(x)');
title(lgd,'My Legend Title')
And I got the same error. I would like some help with this.
  2 comentarios
KSSV
KSSV el 22 de Sept. de 2016
I think the title to legend is supported in MATLAB verison 2016. If you are specific about adding title, you can try keeping string at specified position.
pos = get(lgd,'position') ;
text(pos(1)+1.4,pos(2)+0.16,'My Legend Title') ;
there might be other ways.
Walter Roberson
Walter Roberson el 22 de Sept. de 2016
legend() does not support title in R2016a or R2016b.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Sept. de 2016
legends do not have titles. Axes have titles.
  3 comentarios
Ayush Mishra
Ayush Mishra el 23 de Sept. de 2016
Yes I agree. I wonder why they have not mentioned that on the MATLAB Page.
Walter Roberson
Walter Roberson el 23 de Sept. de 2016
Editada: Walter Roberson el 23 de Sept. de 2016
title has never been a supported attribute for legends. Mathworks does not often document changes affecting only what an object could be "hacked" to do -- using undocumented internal implementations has always been "at your own risk".
Checking further, I find that for legends, you can now use
lgd.Title.String = 'My Legend Title';
so I was wrong about legends not having titles; the official documentation is http://www.mathworks.com/help/matlab/ref/legend-properties.html#property_Title

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by