On Fri, Sep 10, 2010 at 4:27 AM, Nils Wagner
<nwag...@iam.uni-stuttgart.de>wrote:

> Hi all,
>
> what is needed to save a figure when the size is given in
> pixels, i.e. 1024x772 ?
> The default is 800x600 pixels.
>
> from pylab import plot, savefig
> from numpy import sin,linspace,pi
> x = linspace(0,2*pi,200)
> plot(x,sin(x))
> savefig('test')
>
> Nils
>
>
Nils,

In matplotlib, you can specify a figure size in inches like so:

import matplotlib.pyplot as plt
from numpy import sin,linspace,pi

width_in = 10.0
width_px = 1024
height_px = 772
aspect = width_px / float(height_px)
height_in = width_in / aspect
dpi = width_px / width_in

x = linspace(0, 2*pi, 200)
fig = plt.figure(figsize=(width_in, height_in))
ax = fig.gca()
ax.plot(x, sin(x))

Then, when you save your figure, you can specify the "dots per inch" (dpi):

fig.savefig('test.png', dpi=dpi)

I hope this helps!
Ben Root
------------------------------------------------------------------------------
Automate Storage Tiering Simply
Optimize IT performance and efficiency through flexible, powerful, 
automated storage tiering capabilities. View this brief to learn how
you can reduce costs and improve performance. 
http://p.sf.net/sfu/dell-sfdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to