Problem adding text to plot, background color doesn't work properly
29 ビュー (過去 30 日間)
古いコメントを表示
I have encountered a problem using text to put labels inside a plot. I set the background colour to white. This works when I write the text over data plotted with plot, but it doesn't work over lines plotted with xline.
Here's my code:
figure;
plot( datimPingMBRY, timePingMBRY, 'r-' );
hold on;
plot( datimPingMVOFLS2, timePingMVOFLS2, 'b-' );
xline( logItemTime );
datetick( 'x', 'keeplimits' );
yLimits = ylim;
yText = yLimits(2) * 0.2;
t = text( logItemTime, yText*ones(nLogItems,1), string(logItemWhat), ...
'FontSize', 8, 'BackgroundColor', 'w', 'Rotation', 90 );
And here's the plot.
Any suggestions?
0 件のコメント
採用された回答
Star Strider
2023 年 3 月 16 日
The line does not through the label. However it is necessary to specify the label in the xline call —
xl = xline(0.5,'-','X-Line Label');
xl.LabelHorizontalAlignment = 'center';
xl.LabelVerticalAlignment = 'middle';
Also, it is likely more efficient to use datetime arrays than using datenum values (as would appear to be the situation from the datetick call). The xline function can use datetime and duration arguments to define its position.
.
5 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!