How to set size for scatter plot
<p>I have three lines setting a plot. I expect the size of the pic.png to be 640x640 pixels. But I got 800x800 picture. </p>

<pre><code>plt.figure(figsize=(8, 8), dpi=80)
plt.scatter(X[:],Y[:])
plt.savefig('pic.png')
</code></pre>

<p>BTW I have no problem setting size with object-oriented interface but I need to use pyplot style.</p>

<p>While Alberto's answer gives you the correct work around, looking at the <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.savefig" rel="nofollow">documentation for <code>plt.savefig</code></a> gives you a better idea as to why this behavior happens.</p>

<blockquote>
  <p>dpi: [ None | scalar > 0 | âfigureâ]
  The resolution in dots per inch. If None it will default to the value savefig.dpi in the matplotlibrc file. If âfigureâ it will set the dpi to be the value of the figure.</p>
</blockquote>

<p><strong>Short answer:</strong> use <code>plt.savefig(..., dpi='figure')</code> to use the dpi value set at figure creation.</p>

<p><strong>Longer answer:</strong> with a <code>plt.figure(figsize=(8,8), dpi=80)</code>, you can get a 640x640 figure in the following ways:</p>

<ol>
<li><p>Pass the <code>dpi='figure'</code> keyword argument to <code>plt.savefig</code>:</p>

<pre><code>plt.figure(figsize=(8, 8), dpi=80)
...
plt.savefig('pic.png', dpi='figure')
</code></pre></li>
<li><p>Explicitly give the dpi you want to <code>savefig</code>:</p>

<pre><code>plt.figure(figsize=(8, 8))
...
plt.savefig('pic.png', dpi=80)
</code></pre></li>
<li><p>Edit your <a href="http://matplotlib.org/users/customizing.html#the-matplotlibrc-file" rel="nofollow">matplotlibrc file</a> at the following line:</p>

<pre><code>#figure.dpi       : 80      # figure dots per inch
</code></pre>

<p>then</p>

<pre><code>plt.figure(figsize=(8, 8))
...
plt.savefig('pic.png') #dpi=None implicitly defaults to rc file value
</code></pre></li>
</ol>

python matplotlib