How to enlarge/Scale/Increase size of a contour plot
31 次查看(过去 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 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!