필터 지우기
필터 지우기

How to set the plot box to particular size

조회 수: 78 (최근 30일)
Ole
Ole 2021년 9월 24일
답변: Jaswanth 2024년 7월 26일
How to set the plot box to pixel size.
x = linspace(1,20,100);
y = x.^2;
figure(1)
plot(x,y)
xlabel('X')
ylabel('Y')
The code below will set the figure size. Instead I would like only the plot box without labels to have the size of 200x500.
x0=10;
y0=10;
width = 500;
height = 200;
set(gcf,'position',[x0,y0,width,height])

답변 (1개)

Jaswanth
Jaswanth 2024년 7월 26일
Hi,
To set the plot box to a specific pixel size without changing the overall figure size, you can manipulate the Position property of the axes within the figure.
Please refer to the following example code showing how you can achieve a plot box size of 200x500 pixels:
% Add first part of the code you have provided
% Set the figure size
x0 = 10;
y0 = 10;
figure_width = 600; % Adjusted to accommodate the desired plot box size and labels
figure_height = 300; % Adjusted to accommodate the desired plot box size and labels
set(gcf, 'Position', [x0, y0, figure_width, figure_height])
% Set the plot box size
plot_box_width = 500;
plot_box_height = 200;
set(gca, 'Units', 'pixels', 'Position', [50, 50, plot_box_width, plot_box_height])
In the modified code,
  • The figure size is set to 600x300 pixels to provide enough space for the plot box and the labels.
  • The Position property of the axes (gca) is set to [50, 50, 500, 200] pixels. The first two values [50, 50] set the position of the bottom-left corner of the plot box within the figure window, and the last two values [500, 200] set the width and height of the plot box.
Kindlly make sure to adjust the figure size and the position of the plot box as needed to ensure that all elements (including labels) are properly displayed.
I hope the information provided above is helpful.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by