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

23 次查看(过去 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

采纳的回答

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