Double commands required to change figure.axes_size

I have code that I use to draw mechanical parts in which x & y axis must be the same scale and close cropped.
So I set the a.data_bounds, then set f.axes_size so the x:y ratio is the same as a.data_bounds.
The following function doesn’t work unless I set the f.axes_size twice. When I put this code directly in the calling code the results were the same.
What am I missing?

function tight_crop(f, x, y)
	//[xmin,xmax,ymin,ymax]
	f.children.data_bounds =  [x, y];
	dxy = round(diff(x) / diff(y) * f.axes_size(2));
	//why does this double command work??????
	f.axes_size(1) = dxy;
	f.axes_size(1) = dxy;
endfunction

Hello,

A simpler way to lock the aspect ratio to 1:1 is to set to “on” the isoview field of current axes.

S.

1 Like

Thanks mottelet,
That does scale axes.data_bounds appropriately, but leaves the figure outline where it was.
I need to tight crop the figure around the object…
Afterwards I use xs2svg(f, ‘name.svg’), and then remove the white background of the svg file. That leaves just polylines and line segments with no background, which I can use in LibraOffice Draw combined with whatever is drawn in Draw

To be really tight you have to also set the margins to 0 and hide the axis, like in:

clf
[r,t]=meshgrid(linspace(0,1,20),linspace(0,2*%pi,100));
plot(r.*cos(t),r.*sin(t));
a.isoview="on";
xs2svg(0,"original.svg");
xb=[0 0.5];
yb=[0 1];
r=(yb(2)-yb(1))/(xb(2)-xb(1));
a=gca();
a.axes_visible="off";
a.box="off";
a.data_bounds=[xb yb];
a.margins=[0 0 0 0];
gcf().axes_size(1)= gcf().axes_size(2)/r
xs2svg(0,"cropped.svg");


yields the following svg files:

original.svg

cropped.svg