You can tweak the positioning of the axes in the figure window as follows (using your example code):

```
clear all; clc; close all;
x = rand(8,1);
y = rand(8,1);
figure;
ax = handle(gca);
ax.Position = [0.1, 0.15, 0.8, 0.75];
plot(x,y)
xlabel('time (s)')
ylabel('$x$ (m), $\theta$ (rad), $\dot{x}$ (m/s),$\dot{\theta}$ (rad/s), $\dot{S}_{gen}$(W/K)','Interpreter', 'latex','fontsize',10)
grid
```

# Explanation of the code

In `ax = handle(gca);`

you store the axes handle in variable `ax`

such that you can alter it later on.

In `ax.Position [0.1, 0.15, 0.8, 0.75];`

you change the position of the axes in the figure referred by handle `ax`

. The example above sets the lower left point at the coordinates `0.1, 0.15`

and a width and height of `0.8`

and `0.75`

respectively. These coordinates are normalized w.r.t. to your figure size.

# Example plots

## Initial situation

If you set the `ax.Position`

to `[0.25, 0.15, 0.7, 0.75]`

you get something like you had initially:

## Solution

If you set the `ax.Position`

to `[0.1, 0.1, 0.85, 0.85]`

you get far less whitespace:

# Notes

This MATLAB help link explains how you can define the axes position "automatically" such that there is a tighter fit.

This MATLAB help link on axes explains what parameters are available in the axes object.

This answer over at Stackoverflow helped me find a way to use the dot notation in MATLAB versions prior to 2014b. Apparently using `handle()`

is also faster than the `set`

and `get`

methods.

`gcf`

and post it's output (make sure to show all properties) in your questions so we can take a look at it. – Saaru Lindestøkke Dec 5 '18 at 10:35`gcf`

almost produce nothing, only a blank figure wizard is shown and ans = 1 is displayed in the command window – AlFagera Dec 5 '18 at 12:411more comment