Enlarging & Repositioning Figures in MATLAB

In summary: and then sets the position of the colorbar title:lbpos = get(lbpos,'units','normalized','position',[0,1.04]);
  • #1
kelvin490
Gold Member
228
3
I want to create figure that is enlarged, I use:

fig = figure(1);%These two lines maximize the figure dialogue
set(fig,'Units','normalized','Position',[0,0,1,1]);

Then I use zoom(1.9); to enlarge the figure

The dialogue is enlarged. But I want to reposition it just like use the "pan" button. How can I do it programmatically?
 
Physics news on Phys.org
  • #2
Most new versions of Matlab can generate a script for button function.
 
  • #4
Actually my problem is still not solved.
Here's update of my question:
I am trying to plot 3D block which the value is represented by color of each small unit block:

clear; close all; clc;
fig = figure(1);
set (fig, 'Units', 'normalized', 'Position', [0,0,1,1]);
fig_color='w'; fig_colordef='white';
cMap=jet(256); %set the colomap using the "jet" scale
faceAlpha1=1;
faceAlpha2=0.65;
edgeColor1='none';
edgeColor2='none';
NumBoxX=100;%box number in x direction
NumBoxY=100;%box number in y direction
NumBoxZ=5;%box number in z direction

fid = fopen('Stress.dat','r');
datacell = textscan(fid, '%f%f%f%f%f%f%f%f%f%f%f%f%f%f');
fclose(fid);

all_data = cell2mat(datacell);

M=zeros(NumBoxX,NumBoxY,NumBoxZ);

for i=1:NumBoxX
for j=1:NumBoxY
for k=1:NumBoxZ
num=k+NumBoxZ*(j-1)+NumBoxZ*NumBoxY*(i-1);
M(i,j,k)=all_data(num,4); %the forth column of all_data is dislocation density
end
end
end

indPatch=1:numel(M);
[F,V,C]=ind2patch(indPatch,M,'v'); %Call the function ind2patch in order to plot 3D cube with color

title('\sigma_{xy}','fontsize',20);
xlabel('y','fontsize',20);ylabel('x','fontsize',20); zlabel('z','fontsize',20); hold on;
set(get(gca,'xlabel'),'Position',[5 -50 30]);
set(get(gca,'ylabel'),'Position',[5 50 -15]);
set(get(gca,'zlabel'),'Position',[64 190 -60]);
patch('Faces',F,'Vertices',V,'FaceColor','flat','CData',C,'EdgeColor','k','FaceAlpha',0.5);
axis equal; view(3); axis tight; axis vis3d; grid off;
colormap(cMap); caxis([min(M(:)) max(M(:))]);
cb = colorbar;
set(get(cb,'title'),'string','Stress (MPa)','fontsize',20);
lbpos = get(cb,'title'); % get the handle of the colorbar title
set(lbpos,'units','normalized','position',[0,1.04]);
zoom(1.9);

I maximize the dialogue, read data from a file and use a function "ind2patch" found in internet to create boxes each has a color determined by a value assigned to it. At the last part I used zoom(1.9) to enlarge it but I want to shift the whole figure without moving the colorbar.
The following is the original picture before zoomed:
https://www.dropbox.com/s/xashny3w1fwcb2f/small.jpg?dl=0

The following picture is enlarged using zoom(1.9):
https://www.dropbox.com/s/0sfqq1lgo7cm5jd/large.jpg?dl=0
 

1. How do I enlarge a figure in MATLAB?

To enlarge a figure in MATLAB, you can use the "axis" command and specify the desired size. For example, "axis([0 10 0 10])" will resize the figure to be 10 times larger.

2. Can I resize a figure without changing its proportions in MATLAB?

Yes, you can use the "axis" command and specify different values for the x and y limits. For example, "axis([0 10 0 5])" will resize the figure to be 10 times wider and 5 times taller.

3. How do I reposition a figure in MATLAB?

To reposition a figure in MATLAB, you can use the "set" command and specify the "Position" property. For example, "set(gcf,'Position',[100 100 500 500])" will move the figure to the coordinates (100,100) and resize it to be 500x500 pixels.

4. Is there a way to enlarge and reposition multiple figures at once in MATLAB?

Yes, you can use the "subplot" command to create multiple figures in a single window and then use the "axis" and "set" commands to resize and reposition each individual figure.

5. How can I save an enlarged and repositioned figure in MATLAB?

To save a figure that has been enlarged and repositioned in MATLAB, you can use the "saveas" command and specify the desired file format. For example, "saveas(gcf,'myfigure.png','png')" will save the figure as a PNG file.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
504
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top