How to add title to plot annotation

5 Ansichten (letzte 30 Tage)
Brendan Green
Brendan Green am 12 Mär. 2022
Bearbeitet: Scott MacKenzie am 12 Mär. 2022
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 Kommentare
Brendan Green
Brendan Green am 12 Mär. 2022
Apologies for the confusion. The code for the legend title works just fine as @the cyclist has shown, however I am trying to add a title to the annotation textbox as shown below. It seems this may not be possible to do as easily for an annotation textbox.
Scott MacKenzie
Scott MacKenzie am 12 Mär. 2022
Bearbeitet: Scott MacKenzie am 12 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

the cyclist
the cyclist am 12 Mär. 2022
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.

Kategorien

Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by