Annotation box over gridlines in plot

3 次查看(过去 30 天)
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