How to enlarge/Scale/Increase size of a contour plot

조회 수: 21 (최근 30일)
HARISH KUMAR
HARISH KUMAR 2023년 1월 30일
댓글: Walter Roberson 2023년 2월 2일
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

채택된 답변

Walter Roberson
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
HARISH KUMAR
HARISH KUMAR 2023년 1월 30일
Thanks for your response.
It did not understand points you are saying as i am new to matlab. Can you please eloborate for me.
Thanks in advance
Walter Roberson
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
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
  댓글 수: 1
HARISH KUMAR
HARISH KUMAR 2023년 1월 30일
Thanks for your response.
I apologize for not explaining query properly. I was overlaying the contour on a image so i was trying to increase size of contour by 30 pixels to cover sides of my image.
Attaching image for your reference
Thanks in advance

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by