Figures have properties related to Exporting: https://www.mathworks.com/help/matlab/ref/matlab.ui.figure-properties.html#d123e431719
To export figure to pdf, search for print function. To control margins of axes I suggest using tiledlayout.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!