How to enlarge/Scale/Increase size of a contour plot
조회 수: 21 (최근 30일)
이전 댓글 표시
I have a contour plot, i want to increase the size of the contour plot by all the sides ( by 30 pixels). How can it is possible.
Thanks in advance
Much appriciated your efforts
댓글 수: 0
채택된 답변
Walter Roberson
2023년 1월 30일
The contour plot is made as large as possible as will fit inside the axes after taking into account axes labels and tick labels and tickmarks and titles and colorbars.
Turning off axes and tick labels and title and colorbar would increase the size of the area within the axes that is available to draw the contour plot.
Or you could increase the size of the axes. Set the axes Units to pixels, then add 30 to the third and fourth entries of the Position property. However in some cases enlarging the Position can trigger different automatic tick labels so the size of thel contour might not be exactly 30 larger.
A lot of the time when people talk about specific size in pixels, they are using getframe. But getframe records an axes not just the contour plot. Axes size can vary roughly 2 pixels less to 5 pixels more.
So sometimes the solution is to record the contour in an array instead of an axes (a bit of a nuisance but possible), or if one must use getframe then imresize()
댓글 수: 3
Walter Roberson
2023년 2월 2일
img = imresize(imread('flamingos.jpg'), .3);
imsz = size(img);
grey = imresize(rgb2gray(img), [imsz(1)-60, imsz(2)-60]);
grsz = size(grey);
figure(1)
image(img);
hold on
contourf(grey, 10, 'FaceAlpha', .4);
hold off
title('not positioned');
figure(2)
image(img);
hold on
xdata = linspace(1, imsz(2), grsz(2));
ydata = linspace(1, imsz(1), grsz(1));
contourf(xdata, ydata, grey, 10, 'FaceAlpha', .4);
hold off
title('position countour');
figure(3)
xdata = [1 grsz(2)];
ydata = [1 grsz(1)];
image(xdata, ydata, img);
hold on
contourf(grey, 10, 'FaceAlpha', .4);
hold off
title('position imgage')
The "position contour" version involves setting data coordinates for the contour to be the same as the (larger) image. Notice the x runs to over 350 on the middle image.
The "position image" version involves setting data coordinates for the image to be the same as the (smaller) contour. Notice the x runs to a bit over 320 in the bottom image.
추가 답변 (1개)
Tushar Behera
2023년 1월 30일
편집: Tushar Behera
2023년 1월 30일
Hi Harish,
I believe you want to enlarge your contour plot window.
You can acheive this by using "set" function in MATLAB. Below is an example of that
[X,Y,Z] = peaks;
contour(X,Y,Z,20)
figure;
contour(X, Y, Z);
fig = gcf;
% Get current position of the figure window
position = get(fig, 'Position');
% Increase the size of the figure window by 30 pixels on all sides
newPosition = position + [0 0 30 30];
% Set the new position of the figure window
set(fig, 'Position', newPosition);
The "gcf" function returns the handle to the current figure window, and the "get" function retrieves the current position of the figure window. The new position is then calculated by adding [0 0 30 30] to the current position, which increases the size of the window by 30 pixels on all sides. Finally, the "set' function is used to set the new position of the figure window.
I hope this resolves your query.
Regards.
Tushar
참고 항목
카테고리
Help Center 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!