How to create a plot with constant figure size and inner position

199 views (last 30 days)
Hi,
Is it possible to generate a plot, where one is in control of the figure size, and the location of the inner position of the plot and of the figure? Ideally I'd like to control the TightInset parameter, but since that is "read-only", it doesn't seem like an option.
I'm trying to create a plot for a data-sheet, where the sizes of the figure as well of the axes and its position are always the same. Everything should always be in the same postion independently of being active on the plot or not. Generally I'd like the plot to always have the same size and location independant of if I'm using two y-axis, with or without labels, titles, font sizes, etc.
I've dabbled with the different parameters from
and
but there doesn't seem to be an obvious way of doing this.
Regards

Accepted Answer

Aghamarsh Varanasi
Aghamarsh Varanasi on 8 Mar 2021
Hi
You can create plots with a fixed position and a fixed size by setting the 'position' property. By default, 'position' is in pixels.
x0=50;
y0=50;
width=500;
height=400;
set(gcf,'position',[x0,y0,width,height])
You can specify other units (inches, centimeters, normalized, points, or characters). For example:
set(gcf,'units','points','position',[x0,y0,width,height])
  1 Comment
Jesper Bjerregaard
Jesper Bjerregaard on 8 Mar 2021
Thanks for your reply.
Your suggestion alone doens't fix the problem, as the inner parts of the figure change positions when labels, axes, etc are added / removed.
The code below does exactly what I need. Thus combining the inner position parameter of the axes handle with the outer figure size solves the problem. And remember to convert from pixels to points, if you are using pixles, as the figure only supports points.
F=figure('PaperPositionMode','manual');
AX = gca;
F.Resize = 'off';
F.Units = 'points';
F.PaperUnits = 'points';
AX.Units = 'points';
AX.Clipping = 'on';
AX.PositionConstraint = 'innerposition';
AX.InnerPosition = [0 0 FigWidth-BufferWidth FigHeight-Height]*72/96; % converting from pixels to points
F.OuterPosition = [0 0 FigWidth FigHeight]*72/96; % converting from pixels to points
F.PaperPosition = [0 0 FigWidth FigHeight]*72/96;% converting from pixels to points

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!