Axis equal plot in multiple axes GUI

1 visualizzazione (ultimi 30 giorni)
Elando
Elando il 19 Lug 2016
Commentato: Adam il 19 Lug 2016
Hello everybody,
I have a question for you! I have made a code that creates a figure (that initially is invisible) with two axes; in one of the two axes I plot a circle and I need to make this axes with axis equal.
I found on the internet the command axes(..); axis equal, but if I run the code with debugger I saw that when Matlab executes this command, it make the figure visible and I don't need it.
I would need something that make the axis equal, but without showing the figure until the very end of the code when I make it visible; is it possible? Thank you
Here is a simple example that show what happen:
function sample()
f = figure('Visible','off','Position',[300,500,700,500]);
ha = axes('Units','pixels','Position',[50,50,200,400]);
ha_1 = axes('Units','pixels','Position',[300,50,300,400]);
% plot in ha
r = 60;
th = 0:pi/50:2*pi;
x = r*cos(th');
y = r*sin(th');
plot(ha,x,y)
axes(ha); axis equal
f.Units = 'normalized';
f.Visible = 'on';
end

Risposte (1)

Adam
Adam il 19 Lug 2016
Modificato: Adam il 19 Lug 2016
The documentation for the
axis equal
command states that the following axes properties change:
'Sets DataAspectRatio to [1 1 1], sets PlotBoxAspectRatio to [3 4 4], and sets the associated mode properties to manual.'
So you could just set
ha.DataAspectRatio = [1 1 1];
ha.PlotBoxAspectRatio = [3 4 4];
and if it doesn't already do it by doing that ( I can't remember) set
ha.DataAspectRatioMode = 'manual';
ha.PlotBoxAspectRatio = 'manual';
too.
To be honest that specific PlotBoxAspectRatio is a bit of a mystery to me, but that is what it says and I never really play around with those settings to have bothered to learn exactly what that does.
  1 Commento
Adam
Adam il 19 Lug 2016
Alternatively you could just do
axes(ha); axis equal; f.Visible = 'off'
but that is rather ugly - letting it switch the figure visibility on and then over-riding it to switch it off again. It is possible that the user may see this happen too - I haven't tried it, maybe it happens fast enough that the user doesn't see a flicker. I have done it successfully in similar cases.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by