matlabtabsannotationsfiguretabbed

Matlab annotation in tabbed figure


When adding annotations to a Matlab figure, all is well. But when I try to create a tabbed figure (consisting of multiple tabs) the annotations disappear. It seems like they are sent to the background of the image, but I'm not sure how to solve this. Does anybody have a solution? The code I'm using is:

f1 = figure('WindowStyle','normal');
tabgroup = uitabgroup(f1);
tab1 = uitab(tabgroup, 'Title', 'Plot A');
ax1 = axes('Parent', tab1);
plot(1:10,(1:10).^2)
annotation('rectangle',[0.5 0.5 0.1 0.1],'LineWidth',2.5)

I'm using Matlab R2018a


Solution

  • Force the annotation to be on the tab you want:

    annotation(tab1,'rectangle',[0.5 0.5 0.1 0.1],'LineWidth',2.5)