Figure Pixel Resize Function
When presenting data, it is sometimes difficult to maximize the display of all of your plots and minimize the white space. This is particularly evident when presenting multiple plots stacked on top of each other in a column. Matlab will, by default, place large amounts of white space between and around the plots. This resize function can eliminate that white space, or create more of it if desired.
From the help section,
% Resizes plot(s) by specified number of pixels
%
% DESCRIPTION
% Resizes either single plots or plots arranged in a column by number
% of specified pixels. Can be used as either a 'ResizeFcn' for a
% figure or as a direct call to resize a figure
%
% SYNTAX
% figure('ResizeFcn',{@pixel_resize,left,right,top,bottom,spacing,height})
% pixel_resize(notused,notused,left,right,top,bottom,spacing,height,fig_hand)
%
% ARGUMENTS
% notused - this argument is only necessary when calling pixel_resize
% as a function, and is not used in the function at all
% left - number of pixels to the left of the plot(s)
% right - number of pixels to the right of the plot(s)
% top - number of pixels above all of the plots
% bottom - number of pixels below all of the plots
% spacing - number of pixels between plots
% height - normalized height of each plot
% fig_hand - handle of figure to apply pixel_resize
%
% EXAMPLES
% % define resize function for figure
% figure('ResizeFcn',{@pixel_resize,130,10,[],20,0,[0.5 0.25 0.25]})
% x = 0:.01:2*pi;
% y = sin(x);
% for i1 = 1:3
% subplot(3,1,i1)
% plot(x,y)
% end
%
% % use pixel_resize to resize a figure
% fig_hand = figure;
% x = 0:.01:2*pi;
% y = sin(x);
% for i1 = 1:3
% subplot(3,1,i1)
% plot(x,y)
% end
% % applies pixel_resize to gcf
% % pixel_resize(0,0,[],100,20,50,30)
% % applies pixel_resize to figure handle 'fig_hand'
% % pixel_resize(0,0,20,0,70,[],[],[0.2 0.6 0.2],fig_hand)
%
% NOTES
% if normalized spacing is desired, use an empty cell, '[]'
% if there is only 1 plot on the figure, the spacing option will not be
% needed and can either left out of the input arguments (see the
% 2nd syntax option), or left as empty, '[]'
% if pixel_resize is used as a function call, the first 2 arguments are
% not used at all, therefore, they can be anything
% if new spacing is desired, replot the figure and call pixel_resize
% with the new spacing options
% if the height is specified, its vector must add up to 1
%
% Version : 1.2 (10/17/2011)
% Author : Nate Jensen
% Created : 09/23/2011
% History :
% - v1.0 (09/23/2011) : initial release
% - v1.1 (10/03/2011) : added option to call pixel_resize outright
% - v1.2 (10/17/2011) : cleaned up code, added height option
Cite As
Nate Jensen (2024). Figure Pixel Resize Function (https://www.mathworks.com/matlabcentral/fileexchange/32992-figure-pixel-resize-function), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.10.0.0 | I'm sorry about the multiple uploads. I just didn't proof it enough the first 2 times. It should be good now. |
||
1.9.0.0 | v1.2 cleaned up code, added height option |
||
1.8.0.0 | v1.2 cleaned up code, added height option |
||
1.4.0.0 | v1.1 added option to call pixel_resize as a function |
||
1.1.0.0 | v1.01 uploaded old version the first time |
||
1.0.0.0 |