MATLAB Enlarging & Repositioning Figures in MATLAB

AI Thread Summary
To enlarge and reposition figures in MATLAB, the user successfully maximizes the figure window using normalized units and sets its position. However, they seek a method to programmatically shift the entire figure without affecting the colorbar after using the zoom function. The discussion includes attempts to plot a 3D block representation where colors indicate values, utilizing data from a file and a custom function called "ind2patch." The user shares images of the original and zoomed figures to illustrate the issue. They reference external resources for potential solutions but indicate that their problem remains unresolved.
kelvin490
Gold Member
Messages
227
Reaction score
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
Most new versions of Matlab can generate a script for button function.
 
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
 

Similar threads

Replies
1
Views
2K
Replies
3
Views
7K
Replies
5
Views
3K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
1
Views
3K
Replies
4
Views
3K
Back
Top