Annotation box over gridlines in plot

조회 수: 6 (최근 30일)
ga97cad
ga97cad 2021년 12월 7일
댓글: ga97cad 2021년 12월 7일
Hi everyone!
I have a problem with annotation boxes in a 2D plot. I would like to have the annotation box 'over' the grid lines, like it is usual for a legend. I have attached two different fiugres which illustrate my problem to this post. The file "plot_with_grid" has the gridlines over the text in the annotation box which looks a little unprofessional. Is there a way to put the annotation box 'over' the gridlines like the legend?
here's also a sniplet of the code which generates the plot
h=plot(160:10:1200,ft(160:10:1200),'-r');
ax=gca;
hold on
errorbar(x_fit,y_fit,err_y_fit,'ks');
errorbar(x_val,y_val,err_y_val,'bo');
plot(160:10:1200,ft_upper(160:10:1200),'m--');
plot(160:10:1200,ft_down(160:10:1200),'m--');
hold off
ax.XAxis.Limits=[150 1200];
ax.YAxis.Limits=[17 50];
ax.FontSize=12;
xtickangle(45);
%dim=[.68 .6 .3 .3];
dim=[.15 .02 .3 .3];
str={'$h_0$=50 $\mu$m','$T_R$ =20$^\circ$C','$v_w$=0.1 m/min'};
%str={'$h_0=$ $50$ $\mu m$','$T_R =$ $20^\circ C$','$v_w=0.1$ $m/min$'};
annotation('textbox',dim,'String',str,'FitBoxToText','on','Interpreter','latex');
xlabel('Line load $q_L$ in N/mm $\rightarrow$','Interpreter','latex')
ylabel('Thickness $h_{1}$ in $\mu$m $\rightarrow$','Interpreter','latex')
lg=legend ('$Regression$','$Parameterization$ $data$','$Validation$ $data$','$95\%$ $confidence$ $interval$','Interpreter','latex','Location','northeast')
ax.YGrid='off';
Thank you for your help and best regards
Lukas

채택된 답변

Atsushi Ueno
Atsushi Ueno 2021년 12월 7일
You should add 'BackgroundColor','white' as argument of annotation function.
h=plot(0:10:1200,0:10:1200,'-r'); grid on; % as example
annotation('textbox',[.15 .02 .3 .3],'String',{'$h_0$=50 $\mu$m','$T_R$ =20$^\circ$C','$v_w$=0.1 m/min'}, ...
'FitBoxToText','on','Interpreter','latex','BackgroundColor','white'); % <<<< here
legend ('Regression');
  댓글 수: 1
ga97cad
ga97cad 2021년 12월 7일
Hey Atsushi!
that worked perfectly! Thank you very much! I marked your answer as accepted.
Best regards, Lukas

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by