How to reduce the size of a graph to see the title and a legend that are not displayed?

2 次查看(过去 30 天)
i have a graph made in matlab with plot function but the title or legend is not shown because vertically it is very large, how can I make it smaller to be able to visualize the entire graph. Aditionally I have two x axes, one in bottom and the other at the top.
This is the script
%graficas de la biblioteca central
a=xlsread('Libro1.xlsx','H2:H96');
b=xlsread('Libro2.xlsx','AP3:AP171');
c = datenum(fechamec,'dd-mmm-yyyy HH:MM:SS');
figure(1)
plot(c,b,'r')
xlabel('Fecha: año 2020')
ylabel('Temperatura [°C]')
datetick('x', 'dd-mmm')
xtickangle(20)
hold on
d=xlsread('Libro2.xlsx','F3:F171');
e=xlsread('Libro2.xlsx','Y3:Y171');
f=xlsread('Libro2.xlsx','AH3:AH171');
g=xlsread('Libro2.xlsx','AX3:AX171');
h=xlsread('Libro2.xlsx','BG3:BG171');
plot(c,d,'g')
plot(c,e,'m')
plot(c,f,'c')
plot(c,g,'color',[0.9290 0.6940 0.1250])
plot(c,h,'color',[0 0.4470 0.7410])
legend ('T[°C] 4 ventanas cerradas y puerta cerrada','T[°C] 4 ventanas abiertas y puerta abierta','T[°C] 4 ventanas abiertas y puerta cerrada','T[°C] 2 ventanas abiertas y puerta abierta','T[°C] 4 ventanas cerradas y puerta abierta','T[°C] 2 ventanas abiertas y puerta cerrada')
hold off
grid on
ax1 = gca; % este eje deje activo
ax1_pos = ax1.Position; % esto es para ver la posición con respecto al primer eje
ax2 = axes('Position',ax1_pos,'XAxisLocation','top','YAxisLocation','right','Color','none');
x2 = datenum(fechamec,'dd-mmm-yyyy HH:MM:SS');
eje=[0:168];
y2=c'*0+100;
line(x2,y2,'Parent',ax2,'Color','b');
datetick('x', 'HH:MM');
title('Temperatura del Aire Interior en el aula M101');
xlabel('Horas[H]')
ylim([15 40]);
yticks([15 20 25 30 35 40]);
xlim([731222 731229]);
xticks([731222:0.5:731229]);
  5 个评论
dpb
dpb 2021-4-8
Depending on just what he's doing, there have been a couple instances here recently with tiledlayout and extra axes that the defaults have not left sufficient room for...I didn't think to save links, but were forced to reduce the height of the axes and shift the default position a little to make everything fit without clipping.
That's why code would be most helpful so can try to duplicate if it is something not so blatant...
David Espinosa Congo
Hi, could you help me? I need to modify the size of the figure because the tittle isn't showing in my simulation.

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2021-4-15
Try something like this:
figure
plot( ... )
title( ... )
legend( ... )
pos = get(gcf, 'Position')
set(gcf, 'Position',pos+[0 -600 0 600])
Note that it uses the figure 'Position' property, rather than the axes 'Position' property to stretch the figure vertically. Experiment with different values for the vector elements to get different results.
  2 个评论
David Espinosa Congo
It doesn't work, That code modifies the size of the window, but I need to modify the size of the figure inside the window.
Star Strider
Star Strider 2021-4-17
Experiment with the same idea, however using gca instead of gcf. The scale changes, so perhaps:
pos = get(gca, 'Position')
set(gca, 'Position',pos+[0 -pos(2)*0.5 0 pos(2)*0.5])
Or something similar.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by