<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 20, 2017 at 5:38 PM, David Goldsmith <span dir="ltr"><<a href="mailto:eulergaussriemann@gmail.com" target="_blank">eulergaussriemann@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi!  I spent a good part of yesterday trying to figure this out on my own, without success, so I'm posting.  I have a 3601x2401 pixel, 300 DPI figure I export to a png using print_figure; here's sample code:<div><br></div></div></blockquote><div><br></div><div><br></div><div>David,</div><div><br></div><div>If you are trying to write the numpy array directly to a PNG file, an alternative to matplotlib is a package that I created called numpngw: <a href="https://pypi.python.org/pypi/numpngw">https://pypi.python.org/pypi/numpngw</a> (github: <a href="https://github.com/WarrenWeckesser/numpngw">https://github.com/WarrenWeckesser/numpngw</a>).  Both those links show several examples of its use.   numpngw uses just Python and NumPy, so it is easy to install.<br></div><div><br></div><div>Warren</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div><div><pre style="color:rgb(0,0,0);font-family:Menlo;font-size:9pt">PLB.imshow(rslt) # rslt is a 3601x2401 int-valued array<br>curfig = PLB.Figure<br>fig = PLB.gcf() <br># next three lines are in my code; don't seem relevant, but I include them in case they are</pre><pre style="color:rgb(0,0,0);font-family:Menlo;font-size:9pt">ax = fig.gca()<br>ax.xaxis.set_ticks([]) <br>ax.yaxis.set_ticks([])<br><br></pre><pre style="color:rgb(0,0,0);font-family:Menlo;font-size:9pt">fig.canvas.print_figure(fn + <span style="color:rgb(0,128,128);font-weight:bold">'.png'</span>,<br>                        <span style="font-size:9pt;color:rgb(102,0,153)">dpi</span><span style="font-size:9pt">=300,</span></pre><pre style="color:rgb(0,0,0);font-family:Menlo;font-size:9pt">                        bbox_inches<span style="font-size:9pt">=</span><span style="font-size:9pt;color:rgb(0,128,128);font-weight:bold">'tight'</span><span style="font-size:9pt">, </span></pre><pre style="color:rgb(0,0,0);font-family:Menlo;font-size:9pt"><span style="font-size:9pt;color:rgb(102,0,153)">                        pad_inches</span><span style="font-size:9pt">=-</span><span style="font-size:9pt;color:rgb(0,0,255)">1.0 </span><span style="font-size:9pt">/ </span><span style="font-size:9pt;color:rgb(0,0,255)">72)</span></pre><pre style="font-family:Menlo;font-size:9pt"><font color="#000000">The resulting png is neither the right number of pixels by pixels, nor the right number of inches by incheses; what's more the resulting png differs depending on whether I use imshow or matshow (which I also tried).</font></pre><pre style="font-family:Menlo;font-size:9pt"><font color="#000000">What's going on, and how do I "fix" it?  (If I really am getting the full resolution figure, despite what the png is telling me are the pixel counts, why are the physical dimensions off, and why is the png telling me that the pixel counts are different?  If it has something to do with compression, is there some  undocumented way to say "no compression" and will that have the desired effect?)</font></pre><pre style="font-family:Menlo;font-size:9pt"><font color="#000000">Thanks!</font></pre><pre style="font-family:Menlo;font-size:9pt">DLG <br></pre><pre style="color:rgb(0,0,0);font-family:Menlo;font-size:9pt"><span style="font-size:9pt;color:rgb(0,0,255)"><br></span></pre></div></div>
<br>______________________________<wbr>_________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/matplotlib-<wbr>users</a><br>
<br></blockquote></div><br></div></div>