Setting size of a figure

8 Ansichten (letzte 30 Tage)
Ali Baig
Ali Baig am 30 Apr. 2025
Kommentiert: Adam Danz am 30 Apr. 2025
Hi!
I am trying to plot a graph twice: once with axes shown and once without axes. However, this results in two figures with different sizes. I want the two images to have exactly same size (in terms of pixels) and scale, so that when I copy them in to, say MS Word, I can excatly overlap them. I will appreciate your help.
Following is my Matlab script:
clear all
close all
clc
x0 = 10;
y0 = 10;
width = 1000;
height = 1000;
%%%%%%%%%%%%%%%%%%%%%%%%%
x = 0 : 0.001 : 100;
y = sin(x);
%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
plot(x, y);
xlabel('\bfAngular Frequency (Hz)'), ylabel('\bfStorage Modulus (MPa)')
xlim([0 101]), ylim([-1.5 1.5])
set(gcf,'position',[x0, y0, width, height])
exportgraphics(gca, 'With Axis.png', 'Resolution', 600)
%%%%%%%%%%%%%%%%%%%%%%%%%
figure(2)
plot(x, y);
xlabel('\bfAngular Frequency (Hz)'), ylabel('\bfStorage Modulus (MPa)')
xlim([0 101]), ylim([-1.5 1.5])
set(gcf,'position',[x0, y0, width, height])
axis off
exportgraphics(gca, 'Without Axis.png', 'Resolution', 600)

Antworten (1)

Walter Roberson
Walter Roberson am 30 Apr. 2025
You are not exporting the figures: you are exporting the axes, and the axes are different size. The one without the axes does not need to leave room for the labels and ticks.
See the axes property 'InnerPosition'
  1 Kommentar
Adam Danz
Adam Danz am 30 Apr. 2025
+1
There are several additional name-value arguments in exportgraphics that are currently (R2024b) only available in MATLAB Online but will soon (25a-prerelease) be broadly available. These new arguments help control the output size and include Width, Height, Units, Padding, and PreserveAspectRatio.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by