From: Chris Barker <Chris.Barker@no...>  20050930 05:21:47

Hi all, I sent pretty much this question a couple days ago, but it was tacked on to another thread, so it may have gotten lost in the shuffle. So here it is again: This is how I thought MPL works, but it turns out I'm wrong, as the example below indicates. What have I got wrong? 1) The size of a figure is defined in length units (inches), and can be set by: Figure.set_figsize_inches( (w,h) ) 1b) The layout of the figure is defined in "figure units" so it can be scaled by changing the figure size. 2) Size of text, width of lines, etc is defined in terms of length units (points?). 3) When displaying to the screen, or creating an image (PNG) the pixel size of text and line widths, etc is determined by the dpi setting, which is set by: Figure.set_dpi( val ) The trick here is that when printing, it's natural to think in terms of inches, but when creating an image (for a web page, for instance), it is natural to think in terms of pixel size. However, AFAIK, MPL does not have a way to set the pixel size directly. However, changing the dpi of the Figure doesn't seem to have any effect. What's up John? shouldn't Figure.set_dpi effect the dpi of the resulting PNG? I'm using MPL 0.84 on Linux. Chris Enclosed is a sample script, and below are the results: > (7.9749999999999996, 5.6624999999999996) Which should result in a 638 > x 453 Image DPI: 160.0 Size in Inches (7.9749999999999996, > 5.6624999999999996) Which should result in a 1276 x 906 Image DPI: > 160.0 Size in Inches (16.0, 12.0) Which should result in a 2560 x > 1920 Image DPI: 80.0 Size in Inches (16.0, 12.0) > > >  > > > > > #!/usr/bin/env python2.4 > > import matplotlib print "using MPL version:", matplotlib.__version__ > matplotlib.use("WXAgg") > > import pylab import Numeric as N > > x = N.arange(0, 2*N.pi, 0.1) y = N.sin(x) > > > pylab.plot(x,y) F = pylab.gcf() > > # Save with the defaults DPI = F.get_dpi() print "DPI:", DPI Size = > F.get_size_inches() print "Size in Inches", Size print "Which should > result in a %i x %i Image"%(DPI*Size[0], DPI*Size[1]) > F.savefig("test1.png") # this gives me a 797 x 566 pixel image, which > isn't seem right. # these numbers correspond to 100 DPI > > # Now change the DPI: F.set_dpi(160) DPI = F.get_dpi() print "DPI:", > DPI Size = F.get_size_inches() print "Size in Inches", Size print > "Which should result in a %i x %i Image"%(DPI*Size[0], DPI*Size[1]) > F.savefig("test2.png") # this still gives me a 797 x 566 pixel image. > # The DPI of the figure is not being used. > > #Now change the Size: F.set_figsize_inches( (16.0, 12.0) ) DPI = > F.get_dpi() print "DPI:", DPI Size = F.get_size_inches() print "Size > in Inches", Size print "Which should result in a %i x %i > Image"%(DPI*Size[0], DPI*Size[1]) F.savefig("test1.png") # this gives > me a 1600 x 1200 pixel image, # which still corresponds to 100 DPI > > # Now change dpi again: F.set_dpi(80) print "DPI:", F.get_dpi() print > "Size in Inches", F.get_size_inches() F.savefig("test4.png") # Same > image, not change. > > > >  Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 5266959 voice 7600 Sand Point Way NE (206) 5266329 fax Seattle, WA 98115 (206) 5266317 main reception Chris.Barker@... 