How to reduce the size of a graph to see the title and a legend that are not displayed?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/583661/image.png)
5 comentarios
dpb
el 8 de Abr. de 2021
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...
Respuestas (1)
Star Strider
el 15 de Abr. de 2021
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 comentarios
Star Strider
el 17 de Abr. de 2021
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.
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!