Annotation box over gridlines in plot

5 ビュー (過去 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 Center および File ExchangeLegend についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by