Title inside figure plot

166 visualizaciones (últimos 30 días)
John Cruce
John Cruce el 31 de Jul. de 2023
Comentada: Voss el 31 de Jul. de 2023
I have a figure plot with title currently above the figure frame. I'm wanting to remove the white space and border around the figure and move the title to the upper-left of the plot. I'd also like to add text that's right-justified with the title.
What would be the simplest solution for this?

Respuesta aceptada

Voss
Voss el 31 de Jul. de 2023
Something like this?
% a figure, red in color so it can be seen against the white background here:
figure('Color','r')
% some plot:
plot(1:10)
% set the axes position to remove some space around the axes:
set(gca(),'Position',[0.05 0.05 0.93 0.93])
% make a text object for the title:
xl = get(gca(),'Xlim');
yl = get(gca(),'Ylim');
t = text(xl(1),yl(2),'Here is a Title for the Plot', ...
'VerticalAlignment','top', ...
'FontSize',12);
% make a text object for the right-justified text:
ext = get(t,'Extent');
rt = text(ext(1)+ext(3),ext(2),'right-justified text', ...
'HorizontalAlignment','right', ...
'VerticalAlignment','top');
  2 comentarios
John Cruce
John Cruce el 31 de Jul. de 2023
Along these lines, but I'm needing the right-justified text to be on upper right side of the figure and in line with the title text. Basically, I'd like the second line to be in the upper right-hand corner of the figure.
Voss
Voss el 31 de Jul. de 2023
% a figure, red in color so it can be seen against the white background here:
figure('Color','r')
% some plot:
plot(1:10)
% set the axes position to remove some space around the axes:
set(gca(),'Position',[0.05 0.05 0.93 0.93])
% make a text object for the title:
xl = get(gca(),'Xlim');
yl = get(gca(),'Ylim');
t = text(xl(1),yl(2),'Here is a Title for the Plot', ...
'VerticalAlignment','top', ...
'FontSize',12);
% make a text object for the right-justified text:
rt = text(xl(2),yl(2),'right-justified text', ...
'HorizontalAlignment','right', ...
'VerticalAlignment','top', ...
'FontSize',12);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Labels and Annotations en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by