compresson ratio

OK, this does not work for me. Test case:

    > d=arange(201)*pi/100 plot(cos(d),sin(d)) square() show()
    > This should look like a circle. It looks like an oval.

    > Problems: 1. fig.set_figsize_inches is ignored. It has no

Right, I noted this in my original post - if you continue that
post where I posted this code:

    It's the right idea, but it doesn't work currently if you are
    using a GUI backend. The reason it fails is has to do with the
    pipeline order in which figure managers, figures etc are created
    by default, and the fact that configure events and resize events
    change the figure width and height (so you can for example, resize
    your figure window). It *does* work if you specify the figure
    size

    figure(figsize=(8,8))

This is a bug, as I mentioned before, but will require some thought
about how to get this right across backends.

    > 2. axis('equal') should not be desirable, if it is matlab
    > compatible
    > http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axis.html
    > That is, square() should set an axis aspect ratio of unity,
    > but axis('equal') should equate the *unit length* along each
    > axis. (For my example circle this is not a problem, but in
    > generaly this is completely wrong.)

With the amended axes code I'm attaching below, does this example work
as you hope

    from matplotlib.matlab import *
    figure(figsize=(8,8))
    ax = axes([0.1, 0.1, 0.8, 0.8])
    d=arange(201)*pi/100
    plot(10+cos(d),sin(d))
    axis('equal')
    show()

Perhaps more typing than you want for an interactive demo, but does
make everything clear and should work, at least up to the dpix/dpiy
error we discussed earlier.

If it works fine, I'll make it a FAQ. I still have to handle the case
where the axis lim are decreasing...

JDH

def axis(*v):
    """
    axis() returns the current axis as a length a length 4 vector

    axis(v) where v= [xmin xmax ymin ymax] sets the min and max of the
    x and y axis limits

    axis('off') turns off the axis lines and labels

    axis('equal') sets the xlim width and ylim height to be to be
    identical. The longer of the two intervals is chosen
    """
    
    if len(v)==1 and is_string_like(v[0]):
        s = v[0]
        if s.lower()=='on': gca().set_axis_on()
        elif s.lower()=='off': gca().set_axis_off()
        elif s.lower()=='equal':
            ax = gca()
            xmin, xmax = ax.get_xlim()
            ymin, ymax = ax.get_ylim()
            width = xmax-xmin
            height = ymax-ymin
            # TODO: handle decreasing lim
            
            interval = max([width, height])
            ax.set_xlim((xmin, xmin+interval))
            ax.set_ylim((ymin, ymin+interval))
            draw_if_interactive()
            
        else:
            error_msg('Unrecognized string %s to axis; try on or off' % s)
        return
    
    try: v[0]
    except IndexError:
        xlim = gca().get_xlim()
        ylim = gca().get_ylim()
        return [xlim[0], xlim[1], ylim[0], ylim[1]]
    
    v = v[0]
    if len(v) != 4:
        error_msg('v must contain [xmin xmax ymin ymax]')
        return
    gca().set_xlim([v[0], v[1]])
    gca().set_ylim([v[2], v[3]])
    draw_if_interactive()

Hi John,

Since I read your previous message so poorly, I really
appreciate your willingness to communicate again.

At the moment I'm overcaffeinated and underslept, so
I may do as badly again.

I just do not quite "get it" yet. I think I do
not fully understand xlim and ylim.

What I have been doing up to now to get what I need
is to use figsize and 'axes' to determine the aspect
ratio of the viewport (AR(V), the screen area where the
data will be displayed) and then (after the plot)
'axis' to determine the aspect ratio of the viewing window
(AR(W), the relative lengths of the axes in data units).

OK, I see all these same steps, with the only thing
new that instead of having to plug the right numbers
into 'axis', I get a keyword instead. (That "only"
is comparative, not disparaging, of course.)

So here is what I think you are offering: a keyword
that will set the same "width" of data to be displayed
on each axis, so that the AR(W)=1. This means that
I can determine the compression ration CR=AR(W)/AR(V)
from AR(V) alone. And in particular, if I use figsize
and 'axes' to give me AR(V)=1, then axis('equal') will
produce a compression ratio of unity as well.

Do I have that right?

If so:
i. this seems useful
ii. this seems somewhat related to the behavior of
axis('square') in Matlab, if I read the documentation right
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axis.html
iii. This does *not* seem to be like the behavior of
Matlab's axis('equal')

I'm not a Matlab user, but (relying on the documentation)
here is an example of the kind of thing I think you get
from axis('equal') in Matlab:

#define function to graph
def f(x): return 2*x**3-5*x
#choose points in domain for plotting
d=(arange(401)-200.0)/100
#set figure size for plot
figure(1,figsize=(2,5))
#determine AR(V) = AR(W) = 5/2
axes([0.1, 0.1, 0.8, 0.8])
plot(d,f(d))
#determine AR(W) = 5/2
axis([-2,2,-5,5])
show()

Conceptually this works a little backwards, of course.
What you really know first is the AR(W) that you want,
and you choose the AR(V) to yield a compression ratio
of unity (so that the units match along each axis).

So if I have understood correctly, you have indeed offered
something that can be useful, but it should have a different
name. Or this may be overcaffeinated babble. Gotta run...

fwiw,
Alan