Problem adding text to plot, background color doesn't work properly

조회 수: 85 (최근 30일)
dormant
dormant 2023년 3월 16일
댓글: Star Strider 2023년 3월 23일
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?

채택된 답변

Star Strider
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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by