Clear Filters
Clear Filters

How to make the figure size as big as possible on the window screen but with a wanted length-to-width-ratio as A4 paper in R2021b?

11 views (last 30 days)
Hello,
I have used a plotyy code to draw a figure composing several subfigures, and it did work well. The problem is I want to get the complex figure displayed as big as possible on the window screen with a certain length-to-width ratio so that it could be copied to the word document and occupy one page, but the matlab does not respond with the codes designed for that purpose.
Now I could only simply make the figure as big as the window screen by using a "maximize" code which contains the "windowstate" code, but unfortunately my window screen's length-to-width ratio is not suitable for the figure size occupying one page of word document.
Then I also tried to set options for gcf codes other than maximize the figure size to the window screen, but the codes doesn't work at all, the figure size is always displayed in default as a nearly square with medium size compared with the window screen no matter how the options of the gcf set is changed and tried.
I just set the gcf options as follows which is a simplified version for convenience, could anyone kindly help solve this problem? Thank you very much in advance.
load('results.mat', 'oo_')
load -mat a1_1
irf1=oo_.irfs;
save irf1
load irf1
load('results.mat', 'oo_')
load -mat a2_1
irf2=oo_.irfs;
save irf2
load irf2
oad('results.mat', 'oo_')
load -mat a3_1
irf3=oo_.irfs;
save irf3
load irf3
close all
ending_cell={'C','R','X'};
set(gcf, 'PaperOrientation','landscape');
set(gcf, 'PaperUnits', 'normalized');
set(gcf, 'Position', [0.0 0.0 0.8 1]);
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperType', 'A4');
orient rotated;
for ii=1:length(ending_cell)
HOR=1:1:10;
var={'y','X',};
var1={'y_t','X_t',};
figure('Name',strcat(ending_cell{1,ii},'1'))
set(gcf, 'Color','w');
for jj=1:length(var)
subaxis(1,2,jj,'MarginRight',0.03,'MarginLeft',0.03,'MarginBottom',0.03,'SpacingHoriz',0.04,'SpacingVert',0.1)
eval(['irf1.' var{1,jj},ending_cell{1,ii}]);
eval(['irf2.' var{1,jj},ending_cell{1,ii}]);
eval(['irf3.' var{1,jj},ending_cell{1,ii}]);
hold on
plot(HOR,eval(['irf1.' var{1,jj},ending_cell{1,ii}]),'Linestyle','-','Color','k');
addaxis2(HOR,eval(['irf2.' var{1,jj},ending_cell{1,ii}]),'Linestyle','--','Color','r');
addaxis2(HOR,eval(['irf3.' var{1,jj},ending_cell{1,ii}]),'Linestyle','-.','Color','b');
title([var1{1,jj}])
end
saveas(gcf,strcat(ending_cell{1,ii},'_g_1'), 'fig')
saveas(gcf,strcat(ending_cell{1,ii},'_g_1'), 'tiff')
saveas(gcf,strcat(ending_cell{1,ii},'_g_1'), 'eps')
end

Answers (1)

Umar
Umar on 22 May 2024 at 8:43

Based on the code snippet you provided, it seems like you are encountering difficulties in adjusting the size and aspect ratio of a complex figure generated using MATLAB's plotyy function for display in a Word document. The goal is to maximize the figure size on the screen with a specific length-to-width ratio that fits onto a single page in Word. To address this issue, you can follow these steps: 1. *Setting Paper Size and Orientation*: - Use the `set(gcf, 'PaperOrientation','landscape');` command to set the paper orientation to landscape. - Adjust the paper units and size using `set(gcf, 'PaperUnits', 'normalized');`, `set(gcf, 'PaperPositionMode', 'manual');`, `set(gcf, 'PaperType', 'A4');`. - Modify the position of the figure on the paper with `set(gcf, 'Position', [0.0 0.0 0.8 1]);`. 2. *Adjusting Figure Size*: - Instead of using `maximize` code, customize the figure size by setting specific dimensions using `set(gcf, 'Position', [left bottom width height]);`. - Experiment with different width and height values to achieve the desired length-to-width ratio that fits a Word document page. 3. *Saving Figure*: - After customizing the figure size and aspect ratio, save it in multiple formats compatible with Word like '.fig', '.tiff', or '.eps' using `saveas(gcf,'filename','format')`. 4. *Optimizing Subfigures*: - Ensure that each subfigure is properly positioned and scaled within the main figure to maintain clarity and consistency. 5. *Iterative Testing*: - Make iterative adjustments to the figure size, paper settings, and subfigure layout until you achieve the desired result. By following these steps and experimenting with different parameters for figure positioning and dimensions, you should be able to create a complex figure with a specific length-to-width ratio that fits nicely onto a single page in a Word document.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!