How to enlarge/Scale/Increase size of a contour plot
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
HARISH KUMAR
el 30 de En. de 2023
Comentada: Walter Roberson
el 2 de Feb. de 2023
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 comentarios
Respuesta aceptada
Walter Roberson
el 30 de En. de 2023
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 comentarios
Walter Roberson
el 2 de Feb. de 2023
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.
Más respuestas (1)
Tushar Behera
el 30 de En. de 2023
Editada: Tushar Behera
el 30 de En. de 2023
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
Ver también
Categorías
Más información sobre Contour Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!