On Tue, Jan 3, 2012 at 11:57 AM, Mario Fuest <mariofu...@aol.com> wrote:

> Hi,
>
> Maybe a bad idea to ask a question on x-mas. Well, I hope it’s not that
> unpolite to push one‘s questions. :)
>
> Basically I just want to set a fixed width/height on my figure. That
> should be possible?
>
> Mario Fuest <mariofu...@aol.com> schrieb am Sat, 24. Dec 16:42:
> > Hi there,
> >
> > I want to examine a vector field and therefore i used "quiver" to
> > visualize said field:
> >
> > > import numpy as np
> > > import matplotlib.pyplot as plt
> > >
> > > # points
> > > x, y = np.meshgrid(np.arange(0, 2*np.pi, 0.1),
> > >                    np.arange(0, 1*np.pi, 0.1))
> > > # derivatives
> > > dx = -2*np.sin(x)*np.cos(y)
> > > dy =    np.cos(x)*np.sin(y)
> > >
> > > # plot
> > > plt.figure()
> > > plt.quiver(dx, dy, color='b')
> > >
> > > # beautiful axis
> > > a = plt.gca()
> > > x_a, y_a = a.get_xaxis(), a.get_yaxis()
> > > a.axis('tight')
> > > # TODO: We should not multiply with 10 here.
> > > x_a.set_ticks(np.arange(0, 2*np.pi*10+1, np.pi*10/4))
> > > y_a.set_ticks(np.arange(0, 1*np.pi*10+1, np.pi*10/4))
> > > labels = [
> > >     r'$0$',
> > >     r'$\frac{1}{4}\pi$',
> > >     r'$\frac{1}{2}\pi$',
> > >     r'$\frac{3}{4}\pi$',
> > >     r'$\pi$',
> > >     r'$\frac{5}{4}\pi$',
> > >     r'$\frac{3}{2}\pi$',
> > >     r'$\frac{7}{4}\pi$',
> > >     r'$2 \pi$']
> > > a.set_xticklabels(labels)
> > > a.set_yticklabels(labels[:5])
> > >
> > > # show
> > > plt.show()
> >
> > (The plot looks like a double swirl, if anyone is interested in that
> > information)
> >
> > At first I do not know why I have to multiply with 10 at the ticks, but
> > thats not the point.
> >
> > It is much more important that I would like to set the image to a
> > certain width before saving. It should be both "tight" and "equal", so
> > after setting the width the height could be calculated automatically.
> >
> > As a workaround I use the images and strech them vertically, but then
> > the x/y axis tick labels look strange.
> >
> > So: How to set a certain width?
> >
> > Thanks and a merry Christmas,
> > Keba
>
>
You can try

>>> ax.set_aspect('equal')
>>> ax.autoscale(tight=True)

The order doesn't seem to matter.

-Tony
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to