How to add title to plot annotation
Mostrar comentarios más antiguos
I am making a histogram plot to represent data but I am unable to add a title to my annotation textbox. I am able to add a title to my legend with the following code:
lgd1 = legend('Histogram','Mean of Percent Burial','Critical Percent Burial');
lgd_title1 = title(lgd1,'Legend');
This creates a very nice bolded title in the legend and break line between the title and the legend entries. However, similar syntax seems to not work with annotations:
annot1 = annotation('textbox',dim1,'String',str1,'FitBoxToText','on');
annot_title1 = title(annot1,'Results');
The code for the annotation works fine, but using the title function does not work with the following error message:
Unrecognized function or variable 'annot1'.
Is it is possible to include an annotation title similar to legend titles? Or some other work around for this issue.
4 comentarios
Scott MacKenzie
el 12 de Mzo. de 2022
It's not clear what you are trying to do. The 'string' property of an annotation is the title or label for the annotation line. Are you thinking of something different? Perhaps explain with a sketch.
BTW, the first argument of the title function, as you've used it, is a handle to an axis, not a handle to an annotation.
the cyclist
el 12 de Mzo. de 2022
Editada: the cyclist
el 12 de Mzo. de 2022
@Scott MacKenzie, if you execute the first example, you will see that it produces a title for the legend. I assume @Brendan Green is hoping for a similar title for their annotation.
plot(magic(3))
lgd1 = legend('Histogram','Mean of Percent Burial','Critical Percent Burial');
lgd_title1 = title(lgd1,'Legend');
Brendan Green
el 12 de Mzo. de 2022
Scott MacKenzie
el 12 de Mzo. de 2022
Editada: Scott MacKenzie
el 12 de Mzo. de 2022
@the cyclist ah yes. Thanks for the clarification. The handle argument for the title function, if used, is a handle to an object capable of receiving a title. That might be an axis (my response) but it could also be a legend, and maybe some other types of objects. But, it cannot be an annotation, since annotations have no such property.
Respuestas (1)
the cyclist
el 12 de Mzo. de 2022
0 votos
The textbox annotation object does not have a title property, as far as I can tell.
The first work-around that springs to mind is to create a second textbox annotation for the title.
Categorías
Más información sobre Labels and Annotations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

