How to add title to plot annotation

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

Scott MacKenzie
Scott MacKenzie 2022년 3월 12일
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.
@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
Brendan Green 2022년 3월 12일
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 2022년 3월 12일
편집: Scott MacKenzie 2022년 3월 12일
@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.

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2022년 3월 12일

0 개 추천

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.

카테고리

질문:

2022년 3월 12일

편집:

2022년 3월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by