Re: [Matplotlib-users] Adjusting Image size

2010-09-11 Thread Alan G Isaac
On 9/10/2010 5:27 AM, Nils Wagner wrote:
 what is needed to save a figure when the size is given in
 pixels, i.e. 1024x772 ?
 The default is 800x600 pixels.

Did you already get an answer?
My understanding is that you set the figure size in *inches*,
and then by setting its ``dpi`` you determine the number of
pixels.  (So inches are purely virtual, unless you match
the ppi of your display/printer.)

hth,
Alan Isaac


--
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing
http://p.sf.net/sfu/novell-sfdev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Adjusting Image size

2010-09-10 Thread Nils Wagner
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

--
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


Re: [Matplotlib-users] Adjusting Image size

2010-09-10 Thread Tony S Yu

On Sep 10, 2010, at 5:27 AM, Nils Wagner 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

You can try creating a figure with the correct aspect ratio and then setting a 
corresponding dpi when you save:

#---
import matplotlib.pyplot as plt
import numpy as np

plt.figure(figsize=(10.24, 7.72))
x = np.linspace(0,2*np.pi,200)
plt.plot(x, np.sin(x))
plt.savefig('test', dpi=100)
#---

I had mixed results with this: I would occasionally get figures that were one 
pixel smaller than desired.

Best,
-Tony
--
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


Re: [Matplotlib-users] Adjusting Image size

2010-09-10 Thread Benjamin Root
On Fri, Sep 10, 2010 at 4:27 AM, Nils Wagner
nwag...@iam.uni-stuttgart.dewrote:

 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