Borrar filtros
Borrar filtros

How to format a text box annotation?

65 visualizaciones (últimos 30 días)
Ryan Bowman
Ryan Bowman el 1 de Dic. de 2018
Comentada: Adam Danz el 31 de Ag. de 2020
I have an annonation on my image in matlab but I'm trying to have it with green text, a black outline and a purple background. I want my text font to be italic and in the Comic Sans format. Anyone know how to incorporate these characteristics in my code:
davis = imread('DavisHall.jpg');
figure(1), imagesc(davis), axis image
helpdlg(sprintf('Pick four corners of a window in this picture.\nPick top right corner first.\nPick bottom right corner second.\nPick bottom left corner third.\nPick top left corner fourth.'))
PickCorners = ginput(4)
x = [PickCorners(:,1)];
y = [PickCorners(:,2)];
h = gca;
hold(h, 'on');
plot(h, x', y');
plot(h, [x;x(1)]', [y;y(1)]');
dim = [.2 .5 .3 .3];
str = 'Window'
annotation('textbox',dim,'String',str,'FitBoxToText','on');

Respuesta aceptada

Adam Danz
Adam Danz el 1 de Dic. de 2018
Editada: Adam Danz el 31 de Ag. de 2020
You need the handle to the annotation object.
Once you have the handle, you can see the list of editable properties.
ah = annotation('textbox',dim,'String',str,'FitBoxToText','on');
Now look at all of the properties by executing 'ah' in the command window.
ah.Color = 'g'; %or = [0 .5 0] Green text
ah.FontName = 'Comic Sans MS'; %use listfonts command to see list of available fonts
ah.BackgroundColor = [.5 0 .5]; %purple background
EdgeColor will set the box color but it's already black when it's created.
  4 comentarios
micholeodon
micholeodon el 31 de Ag. de 2020
Editada: micholeodon el 31 de Ag. de 2020
I wonder why formatiing below not works (text is not aligned in plot):
figure
nlogl = randn; mi = randn; ma = randn;
dim = [0.37 0.15 0.4 0.3];
str = sprintf('\n NLOGL\t = %+8.2f \n min\t = %+8.2f \n max\t = %+8.2f', nlogl, mi, ma);
txtbox = annotation('textbox', dim, 'String', str, 'FitBoxToText', 'on');
txtbox.FontName = 'FixedWidth';
Am I doing sth wrong?
When I type
str
in Command Window it displays nicely aligned text.
Adam Danz
Adam Danz el 31 de Ag. de 2020
Remove the spaces following "\n".
str = sprintf('NLOGL\t = %+8.2f \nmin\t = %+8.2f \nmax\t = %+8.2f', nlogl, mi, ma);

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by