# Double commands required to change figure.axes\_size

**URL:** <https://scilab.discourse.group/t/double-commands-required-to-change-figure-axes-size/415>\
**Category:** Graphics and plotting\
**Created:** [February 28, 2024, 6:35pm UTC](https://scilab.discourse.group/t/double-commands-required-to-change-figure-axes-size/415 "2024-02-28T18:35:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@Steve](https://scilab.discourse.group/u/Steve)\
**Post date:** [February 28, 2024, 6:35pm UTC](https://scilab.discourse.group/t/double-commands-required-to-change-figure-axes-size/415/1 "2024-02-28T18:35:15Z")

</div>

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?

```auto
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

```

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [February 29, 2024, 9:52am UTC](https://scilab.discourse.group/t/double-commands-required-to-change-figure-axes-size/415/2 "2024-02-29T09:52:43Z")

</div>

Hello,

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

S.

---

<div class="post-metadata">

**Author:** ![Steve](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@Steve](https://scilab.discourse.group/u/Steve)\
**Post date:** [March 7, 2024, 12:29am UTC](https://scilab.discourse.group/t/double-commands-required-to-change-figure-axes-size/415/3 "2024-03-07T00:29:43Z")

</div>

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

 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/eb52772e5d85a8290467e03f487b7e0e22509735.png)

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [March 7, 2024, 7:56am UTC](https://scilab.discourse.group/t/double-commands-required-to-change-figure-axes-size/415/4 "2024-03-07T07:56:42Z")

</div>

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

```auto
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

 ![](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/830e0fe20c7f1c25cfc9a6038a4655c329c11b32.svg)

### cropped.svg

 ![](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/c3b7ce775e8819506b1e3f63a8e24768a6f27887.svg)
