Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to prevent changing axes appearance?

Subject: How to prevent changing axes appearance?

From: someone else

Date: 22 Mar, 2013 14:52:22

Message: 1 of 8

Hi,

my code gives two sorts of different results.

A last step in finishing the figure (before print) is realigning the axes y position and height whilst keeping x position and width. I do use get and set position for that.

The only circumstance to affect this behaviour I can think of is this one:
If I manually run parts of the code, I mean if I work out the figure and it actually pops up on screen, and only then run the last print block of code, I get precisely what it should be.
If I however, run the code as a whole calling its name from the command window (or even evaluate the last section as a whole) the resulting picture is wrong: axes x positions and widths are resized.

I can't do it the manual piece-wise way for a large number of pictures :( I believe the code is missing a command which would prevent axes from resizing when the figure windows doesn't pop up.

I tried to read about axes details but I don't see which one would apply to this problem.
I keep unchanged the ActivePositionProperty which is I think Position which is fine as the code controls this property.
Maybe it has to do with the aspect ratio, but I don't see how to set it.

Does anyone know to help? Thank you so much!

Subject: How to prevent changing axes appearance?

From: dpb

Date: 22 Mar, 2013 14:56:14

Message: 2 of 8

On 3/22/2013 9:52 AM, someone else wrote:
...

>
> A last step in finishing the figure (before print) is realigning the
> axes y position and height whilst keeping x position and width. I do use
> get and set position for that.
>
> The only circumstance to affect this behaviour I can think of is this one:
> If I manually run parts of the code, I mean if I work out the figure and
> it actually pops up on screen, and only then run the last print block of
> code, I get precisely what it should be.
> If I however, run the code as a whole calling its name from the command
> window (or even evaluate the last section as a whole) the resulting
> picture is wrong: axes x positions and widths are resized.
>
> I can't do it the manual piece-wise way for a large number of pictures
> :( I believe the code is missing a command which would prevent axes from
> resizing when the figure windows doesn't pop up.
>
> I tried to read about axes details but I don't see which one would apply
> to this problem.
> I keep unchanged the ActivePositionProperty which is I think Position
> which is fine as the code controls this property.
> Maybe it has to do with the aspect ratio, but I don't see how to set it.
>
> Does anyone know to help? Thank you so much!

Think need a (as short as possible) sample of the plot code that
illustrates the problem and how you're generating the plots.

If you set the physical size of the axes directly, I can't otomh see
where it would ever be different. If you just use the default window
sizes and manually fiddle around, then obviously things happen in
callbacks behind the scenes...

--

Subject: How to prevent changing axes appearance?

From: someone else

Date: 22 Mar, 2013 18:48:13

Message: 3 of 8

> Think need a (as short as possible) sample of the plot code that
> illustrates the problem and how you're generating the plots.
>
> If you set the physical size of the axes directly, I can't otomh see
> where it would ever be different. If you just use the default window
> sizes and manually fiddle around, then obviously things happen in
> callbacks behind the scenes...

Hi,

thank you for reply, dpb.

This is a brief idea of the code:
1. A toolbox function (not distributed with ML) opens a new figure and creates a set of subplots.
I work out the figure and font size, the figure contains everything except for a legend.
(gcf,'Units','centimeters','Position',[3 3 wd ht]);

2. I call my own function (an .m file in current directory) to create a legend and realign the axes y position and width (as does e.g. gridLegend), something like:
axp = get(hax,'Position');
naxp = axp;
naxp(2) = naxy;
naxp(4) = naxh;
set(hax,'position',naxp);

3. The last part of the script is the print block:
set(gcf,'PaperUnits','centimeters');
set(gcf,'PaperSize',[wd ht]);
set(gcf,'PaperPositionMode','auto');
set(gcf,'PaperPosition',[0 0 wd ht]);
print(gcf,'-depsc2','-r600',sprintf('%s.eps',fnm));

Manually running the code piece-wise: I mean, I evaluate 1. which lets the figure window pop up on screen. I do NOT click on it, move it, enlarge on screen, use edit plot, nothing. (It is not figure preview pane). Then I evaluate 2. and 3. This gives the perfect result.

Running the script as a whole: I evaluate 1.,2. and 3. This causes the axes x position and height change.

Maybe the backend function(s) that are used for plotting (it is hard for me to see them) include sorts of commands that will re-adjust axes x position and width, if one realigns axes y position and heigth.

Anyway, the thing appears to be sensitive on the figure popping up on screen, before the axes realignment is applied. I don't know how to describe it better...

Do you have ideas what could it be? Help is appreciated a lot.

Thank you.

Subject: How to prevent changing axes appearance?

From: someone else

Date: 22 Mar, 2013 18:54:09

Message: 4 of 8

Pardon, typos:
... realign the axes y position and height (as does ...

... This causes the axes x position and width change.

Subject: How to prevent changing axes appearance?

From: dpb

Date: 22 Mar, 2013 20:47:22

Message: 5 of 8

On 3/22/2013 1:54 PM, someone else wrote:
> Pardon, typos:
> ... realign the axes y position and height (as does ...
>
> ... This causes the axes x position and width change.

As said before I think w/o an actual piece of code someone else can
execute that demonstrates the problem it'll be unlikely to find out
what's actually happening.

Verbal descriptions generally just aren't precise enough to duplicate.

--

Subject: How to prevent changing axes appearance?

From: someone else

Date: 23 Apr, 2013 13:12:07

Message: 6 of 8

dpb <none@non.net> wrote in message <kiig0n$cmr$1@speranza.aioe.org>...
> As said before I think w/o an actual piece of code someone else can
> execute that demonstrates the problem it'll be unlikely to find out
> what's actually happening.
>
> Verbal descriptions generally just aren't precise enough to duplicate.

Well, dpb, this was the code... I forgot to post reply, my apologies.

I correctly noticed that being auto the three modes (data aspect ratio, plot box aspect ratio and camera view angle) will enable ML to stretch the axes to fill the rectangle as given by the position. The axes behaviour, however, is also influenced by the axes lim mode. I learned from the developer that the particular function used for plotting sets manually 'xLimMode'. This is for reasons and trying to change that would yield problems.

For the case it might be useful to any of you: Even with manual 'xLimMode' I could well use my function to reposition the legend and realign the axes: I finished all plotting in the figure, let open and close another figure (to pause) and only then call my function. Stupid, but it worked and preserved those toolbox function preset properties.

Thanks again, dpb, for your interest in helping with that. Old good lord, you helped to solve a couple of other problems in the past, though under different nickname.

Subject: How to prevent changing axes appearance?

From: dpb

Date: 23 Apr, 2013 14:32:49

Message: 7 of 8

On 4/23/2013 8:12 AM, someone else wrote:
...> Thanks again, dpb, for your interest in helping with that. Old good
> lord, you helped to solve a couple of other problems in the past, though
> under different nickname.

Not likely it was I posting under anything else but my initials, no...

--

Subject: How to prevent changing axes appearance?

From: someone else

Date: 23 Apr, 2013 16:14:09

Message: 8 of 8

> Not likely it was I posting under anything else but my initials, no...

Me.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us