controlling aspect ratio

Hello,

I would like to (mis-)use matplotlib to draw some things which
are not graphs of functions. For this it would be nice to
be able to fix the aspect ratio of the figure to 1. What is
a good way to do so?

Jochen

···

--
http://seehuhn.de/

Hi there,
I'm not suggesting that this is a good way to to so, but it works (the
last time I tried). Hope this helps.

def setDataAspectRatioByFigSize(ax,r):
    """Same idea as matlab. Adjusts the figure size to fix the aspect
ratio"""
    xlim=ax.get_xlim()
    dxlim=xlim[1]-xlim[0]
    ylim=ax.get_ylim()
    dylim=ylim[1]-ylim[0]
    pos=ax.get_position()
    dxpos=pos[2]
    dypos=pos[3]
    f=gcf()
    figsize=f.get_size_inches()
    dxfig=figsize[0]
    dyfig=dylim*dxpos*dxfig/r/dypos/dxlim
    f.set_figsize_inches(dxfig,dyfig)

def setDataAspectRatioByAxisPos(ax,r):
    """Same idea as matlab. Adjusts the axis position to fix the aspect
ratio"""
    xlim=ax.get_xlim()
    dxlim=xlim[1]-xlim[0]
    ylim=ax.get_ylim()
    dylim=ylim[1]-ylim[0]
    pos=ax.get_position()
    dxpos=pos[2]
    dypos=pos[3]
    centreypos=pos[1]+0.5*dypos
    f=gcf()
    figsize=f.get_size_inches()
    dxfig=figsize[0]
    dyfig=figsize[1]
    dypos=dylim*dxpos*dxfig/r/dyfig/dxlim
    ax.set_position([pos[0],centreypos-0.5*dypos,dxpos,dypos])

Cheers,
Cory

···

On Mon, 2004-11-01 at 16:02, Jochen Voss wrote:

Hello,

I would like to (mis-)use matplotlib to draw some things which
are not graphs of functions. For this it would be nice to
be able to fix the aspect ratio of the figure to 1. What is
a good way to do so?

Jochen

--
))))))))))))))))))))))))))))))))))))))))))))
Cory Davis
Meteorology
School of GeoSciences
University of Edinburgh
King's Buildings
EDINBURGH EH9 3JZ

ph: +44(0)131 6505092
fax +44(0)131 6505780
cdavis@...372...
cory@...374...
http://www.geos.ed.ac.uk/contacts/homes/cdavis
))))))))))))))))))))))))))))))))))))))))))))

http://sourceforge.net/mailarchive/forum.php?thread_id=5562487&forum_id=33405

hth,
Alan Isaac

···

On Mon, 1 Nov 2004, Jochen Voss apparently wrote:

I would like to (mis-)use matplotlib to draw some things which
are not graphs of functions. For this it would be nice to
be able to fix the aspect ratio of the figure to 1. What is
a good way to do so?

Hello Cory,

···

On Mon, Nov 01, 2004 at 04:24:34PM +0000, Cory Davis wrote:

I'm not suggesting that this is a good way to to so, but it works (the
last time I tried). Hope this helps.

Thank you very much, it works beautifully.

All the best,
Jochen
--
http://seehuhn.de/

Hello Alan,

···

On Mon, Nov 01, 2004 at 11:52:07AM -0500, Alan G Isaac wrote:

http://sourceforge.net/mailarchive/forum.php?thread_id=5562487&forum_id=33405

Thanks, this looks incredibly useful.
I will have a closer look as soon as I find time.

All the best,
Jochen
--
http://seehuhn.de/