How can I fix the size of graph in GUI?

11 views (last 30 days)
Maybe go to EDITED2 at the end of this post.
I have application in GUI with 3 push buttons, 1 object axes1 . It has edit text for change XLim,YLim of graphs.
  • If I draw graph, then I change X limits (or Y limits) from default value to my value and sometimes it makes the graph smaller (never makes the graph bigger than axes1, but smaller than axes1).
How I can fix the size of graph in object axes1 ? I try put this to the pushbutton function, but it doesn´t any effect:
set (handles.axes1,'Position',[60 10 40 20]);
EDITED: So this makes the graph smaller only when I use function zplane(b). Do you have same idea how to repair it? You can try this, if you create 1x push button for function, 2x push buttons for set limits and 4x edit text.
Here is the problem part of code for pushbutton of function zplane:
cla;
b=[5 12]
subplot(1,1,1),zplane(b);
hold off;
For pushbutton to set limit X axis:
num_Xmin = str2double(get(handles.edit1,'String'));
num_Xmax = str2double(get(handles.edit2,'String'));
set(gca, 'XLim',[num_Xmin num_Xmax]);
For pushbutton to set limit Y axis:
num_Ymin = str2double(get(handles.edit3,'String'));
num_Ymax = str2double(get(handles.edit4,'String'));
set(gca, 'YLim',[num_Ymin num_Ymax]);
EDITED2: If you start my attached file, click on button zplane, then set ylimits from 5 to 300 and push the button y limits. Graph will be smaller. That is my problem. Can somebody help me?

Accepted Answer

per isakson
per isakson on 1 Jul 2014
Edited: per isakson on 1 Jul 2014
It's DataAspect that causes the behaviour
100 set(gca, 'XLim',[num_Xmin num_Xmax]);
K>> get(gca)
...
DataAspectRatio = [1 1 1]
DataAspectRatioMode = manual
add the lines (or similar)
set( gca, 'DataAspectRatioMode', 'auto' )
set(gca, 'XLim',[-2,2]);
set(gca, 'YLim',[-2,2]);
at the end of pushbutton3_Callback
  1 Comment
Borek
Borek on 2 Jul 2014
Thank you, your answer was helpful. I was combinated your code with code for set position and its working:
set( gca, 'DataAspectRatioMode', 'auto' )
set(gca,'Position',[0.06, 0.22, 0.78 0.74]);
%value 1 is 100 percents? Vector is [left bottom width height]
set(gca, 'XLim',[-2,2]);
set(gca, 'YLim',[-2,2]);
Once again, thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!