Enlarging & Repositioning Figures in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter kelvin490
  • Start date Start date
  • Tags Tags
    figure matlab plot
Click For Summary

Discussion Overview

The discussion revolves around how to enlarge and reposition figures in MATLAB, particularly focusing on programmatic methods to manipulate figure properties and achieve desired visual outcomes in 3D plots. Participants explore various techniques and share resources related to figure manipulation.

Discussion Character

  • Technical explanation
  • Exploratory
  • Homework-related

Main Points Raised

  • One participant describes using the 'set' function to maximize a figure and applies zoom to enlarge it, but seeks a way to reposition the figure programmatically.
  • Another participant mentions that newer versions of MATLAB can generate scripts for button functions, implying potential for automation.
  • A participant references a MathWorks link that may provide a solution to the enlargement issue, suggesting that others have encountered similar problems.
  • A follow-up post details a specific 3D plotting scenario, including data handling and visualization techniques, while reiterating the need to shift the entire figure without affecting the colorbar.
  • One participant shares a Stack Overflow link that discusses programmatically invoking the pan tool, which may relate to the repositioning challenge faced by the original poster.

Areas of Agreement / Disagreement

Participants do not reach a consensus on a specific solution for repositioning figures. Multiple approaches and resources are suggested, but the discussion remains unresolved regarding the best method to achieve the desired outcome.

Contextual Notes

Some limitations include the dependence on MATLAB version for certain functionalities, and the specific requirements of the figure manipulation may not be fully addressed by the shared resources.

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 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K