Re: Position and DataAspectRatio



Peter Boettcher wrote:
>
>
> "David Epstein" <dbae@xxxxxxxxxxxxxxxxxxxxxxxxxx> writes:
>
>> A CHALLENGE
>> ***********
>>
>> The few of you who are following this thread may have the
> impression
>> that my complaint is about the detailed wording of the
> documentation.
>> Anyone who thinks this should try the following task. Consider
> the
>> code:
>>
>> clear all; close all;
>> set(gcf,'Position',[30,30,560,420]);
>> set(gca,'Position',[0,0.1100,0.7750,0.8150]);
>> set(gca,'DataAspectRatio',[1,1,1]);
>> %code written by your colleague, recently deceased
>>
>> Actually, I want you to imagine that these values for these
> Positions
>> arose, not as a result of typing in, as here, but rather as a
> result
>> of 10000 lines of code. You have not the slightest idea how the
>> values arose. You have observed (using get(gca) and get(gcf))
> that
>> they change when the input to your colleague's program is
> changed.
>> Your boss shows you the output figure and says "Please produce
> code
>> that will supply an immediately adjacent (that is, touching)
> white
>> box, of the same height as the existing white box, and aligned
> with
>> it at bottom and top, filling 3/4 of the horizontal space
> remaining
>> in the figure. Another thing, I've had enough of
incomprehensible
>> code. This is clearly a trivial task for a graphics system as
>> powerful as Matlab's and for a programmer as skilled in Matlab
as
> I
>> know you to be. Your code should be comprehensible to someone
who
>> understands Matlab well, even if you omit the comments."
>
> As requested, with no comments.
>
> set(gca, 'Units', 'pixels');
> p = get(gca, 'Position');
> if(p(3) - p(4) > 0)
> p(1) = p(1) + (p(3) - p(4)) / 2;
> p(3) = p(4);
> else
> p(2) = p(2) + (p(4) - p(3)) / 2;
> p(4) = p(3);
> end
>
> set(gca, 'Position', p);
>
> figp = get(gcf, 'Position');
> newp = p;
> newp(1) = p(1) + p(3);
> newp(3) = .75*(figp(3) - newp(1));
> axes('Units', 'pixels', 'Position', newp);
>
>
> --
> Peter Boettcher <boettcher@xxxxxxxxxx>
> MIT Lincoln Laboratory
> MATLAB FAQ: <http://www.mit.edu/~pwb/cssm/>
>
Peter's solution is good. I had a similar solution in mind, but much
less elegantly expressed. So I owe you a beer, if I ever get to meet
you in person, Peter!

I realize I'm being very picky, and I'll try my best to restrain
myself from making this thread even longer in the future, but I would
like to point out that, as I anticipated in an earlier post, an
undocumented aspect of Matlab is being used in Peter's code. It LOOKS
as though what Matlab is doing is using "subtract height from width
and divide by two", but you don't really KNOW this. Just checking on
a few cases doesn't prove that this is what it will always do.

Is it not possible that a similar problem might be met when the
dataaspectratio is set to 1 1 1 and the shape required by XLim and
YLim is inconsistent with Position? I won't have the temerity to ask
for the code after all this palaver...I wouldn't use it anyway. I DO
plan to use the code Peter actually posted (thanks), the square case.
Could I just ask Peter whether his code would have to be much
complicated to meet this case? You can leave me to figure it out with
a simple "Yes" or "No".

One of the things I learned from Peter's posting was the advantage,
for some problems, of using pixels, or some other fixed length, as
Units.

Thanks
David
.



Relevant Pages

  • Re: writing user specified files
    ... help not to be lectured on my proficiency in MATLAB. ... Peter "lectured" you on anything. ... Peter's style, and my style, and John D'Errico's ... from Peter or John or I (or from Roger Stafford, ...
    (comp.soft-sys.matlab)
  • Re: Int 32 processing speed: Is it a bug
    ... The overly complicated statement in the doc, as pointed out by Peter ... In addition, as pointed out by others, the saturating model on overflow ... These days MATLAB is a complicated beast, ...
    (comp.soft-sys.matlab)
  • Re: Position and DataAspectRatio
    ... > I note that Peter, as an experienced Matlab programmer, changes, at ... > graphics properties into consistent values. ... Peter Boettcher ...
    (comp.soft-sys.matlab)
  • Re: Efficient creation of large matrices
    ... I think you partially misread my question Peter. ... slower than the first method. ... This assumes x is a column vector, and I append the one so that the ... might want to read through the "Getting Started" part of the MATLAB ...
    (comp.soft-sys.matlab)
  • Re: Improve DrawString Quality on 480 X 640 Pocket PCs
    ... And sizing fonts that small is going to give you a certain amount of grainy ... There just aren't enough pixels in the available character ... I'd guess that Peter has ... > Windows Embedded MVP ...
    (microsoft.public.dotnet.framework.compactframework)