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

85 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Star Strider
Star Strider el 16 de Mzo. de 2023
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 comentarios

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by