- 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.
How to set the plot box to particular size
조회 수: 78 (최근 30일)
이전 댓글 표시
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])
댓글 수: 0
답변 (1개)
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,
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.
Kindly refer to the following MathWorks documentation to know more about the Position Name-value argument of figure function: https://www.mathworks.com/help/matlab/ref/figure.html?searchHighlight=figure&s_tid=srchtitle_support_results_1_figure#:~:text=Position%20%E2%80%94%20Location%20and%20size%20of%20drawable%20area
I hope the information provided above is helpful.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!