|
From: Chris B. <Chr...@no...> - 2005-09-30 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) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chr...@no...
|
|
From: John H. <jdh...@ac...> - 2005-09-30 13:36:24
|
>>>>> "Chris" == Chris Barker <Chr...@no...> writes:
Chris> Hi all, I sent pretty much this question a couple days ago,
Chris> but it was tacked on to another thread, so it may have
Chris> gotten lost in the shuffle. So here it is again:
Sorry Chris, I got half way through answering this a few days ago but
had to take off midstream, and though I thought I had saved the post,
it was lost. Trying again.
Chris> This is how I thought MPL works, but it turns out I'm
Chris> wrong, as the example below indicates. What have I got
Chris> wrong?
Chris> 1) The size of a figure is defined in length units
Chris> (inches), and can be set by:
Chris> Figure.set_figsize_inches( (w,h) )
Yep.
Chris> 1b) The layout of the figure is defined in "figure units"
Chris> so it can be scaled by changing the figure size.
Not sure what this means, but you can change the figure size and the
layout (eg axes positions) will update.
Chris> 2) Size of text, width of lines, etc is defined in terms of
Chris> length units (points?).
Yes, points.
Chris> 3) When displaying to the screen, or creating an image
Chris> (PNG) the pixel size of text and line widths, etc is
Chris> determined by the dpi setting, which is set by:
Chris> Figure.set_dpi( val )
Yep. But you have to be careful here, because savefig has it's own
default dpi, so when creating hardcopy you will need to explicitly set dpi.q
Chris> The trick here is that when printing, it's natural to think
Chris> in terms of inches, but when creating an image (for a web
Chris> page, for instance), it is natural to think in terms of
Chris> pixel size. However, AFAIK, MPL does not have a way to set
Chris> the pixel size directly.
It does now. In 0.84 I added a canvas.resize(w,h) in pixels. So far
this has only been implemented in GTK*. If anyone wants to help with
the other backends, that would be great. See the thread on the dev
list "GUI maintainers: canvas.resize and ResizeEvent"
With the changes in that post, you can dynamically resize the canvas
or figure, eg from the interactive shell, and the GUI figure window
will update, as it should.
Chris> However, changing the dpi of the Figure doesn't seem to
Chris> have any effect. What's up John? shouldn't Figure.set_dpi
Chris> effect the dpi of the resulting PNG? I'm using MPL 0.84 on
Chris> Linux.
See the comment on savefig above.
Cheers,
JDH
|
|
From: Chris B. <Chr...@no...> - 2005-09-30 16:23:00
|
John Hunter wrote:
> Sorry Chris, I got half way through answering this a few days ago but
> had to take off midstream, and though I thought I had saved the post,
> it was lost. Trying again.
thanks, you're usually so responsive, I was surprised!
> Chris> Figure.set_dpi( val )
>
> Yep. But you have to be careful here, because savefig has it's own
> default dpi, so when creating hardcopy you will need to explicitly set dpi.q
So what is figure.dpi used for? And I need to ask, why doesn't savefig
default to the Figure dpi?
Thanks. I think I'll update my demo and maybe post it to the Wiki.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chr...@no...
|
|
From: John H. <jdh...@ac...> - 2005-09-30 16:32:06
|
>>>>> "Chris" == Chris Barker <Chr...@no...> writes:
Chris> So what is figure.dpi used for? And I need to ask, why
Chris> doesn't savefig default to the Figure dpi?
Well, it's used to control the figure dpi <wink>. It is used
everywhere, it's just that savefig changes it when saving and then
restores it. Basically, it is done this way to support a default
screen dpi and a default hardcopy dpi.
Chris> Thanks. I think I'll update my demo and maybe post it to
Chris> the Wiki.
Thanks,
JDH
|
|
From: Chris B. <Chr...@no...> - 2005-09-30 18:55:51
|
John Hunter wrote:
> Well, it's used to control the figure dpi <wink>. It is used
> everywhere, it's just that savefig changes it when saving and then
> restores it. Basically, it is done this way to support a default
> screen dpi and a default hardcopy dpi.
Fair enough, but my expectation is that when I called savefig, I'd get
the same resolution as the screen, unless I specified otherwise. If
savefig used the Figure dpi as the default, but allowed it to be
overridden (like it does) then we could all be happy. However, if
there's one thing I've learned about usability, it's that different
people have different expectations, so what you have might fit other
peoples expectations better, and we can all do what we need to do.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chr...@no...
|
|
From: Chris B. <Chr...@no...> - 2005-10-02 16:21:17
|
Chris Barker wrote: > I think I'll update my demo and maybe post it to the Wiki. Done. http://www.scipy.org/wikis/topical_software/AdjustingImageSize -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |
|
From: Chris B. <Chr...@no...> - 2005-10-02 20:51:37
|
One more thought:
John Hunter wrote:
> However, AFAIK, MPL does not have a way to set
> Chris> the pixel size directly.
>
> It does now. In 0.84 I added a canvas.resize(w,h) in pixels. So far
> this has only been implemented in GTK*.
What about with savefig()? As long as we can set ppi there, it would be
nice to set a pixel size of the Figure as well.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chr...@no...
|