The meaning of the figure(dpi=xxx) parameter

In order to get the size of the overall plot window to

    > anywhere near full screen, I've had to use something like

    > figure(1, figsize=(18,12), dpi=72) or figure(1,
    > figsize=(9,6), dpi=144)

    > Both produce the same overall size plot window (11.25" wide by
    > 8" tall), but in the latter case, the text size is much larger
    > than in the latter case. Likewise the linewidths.

    > Can you please explain the interaction among the dpi value,
    > the font sizes displayed, and the overall plot size.

Hi Al,

This is a complicated issue and I don't have a full answer for you.
The problem is compounded by the fact that I am trying to make the DPI
parameter produce figures that look the same across the backends, and
different backends have often have an additional parameter that makes
assumptions about the number of pixels per inch on your display - eg
gd assumes 96, and these are not under my control.

The total figure width in pixels is figure width in inches * dpi;
ditto for height. If you set dpi to your device PIXELS_PER_INCH, the
width should be correct if you measure it on the screen with a ruler.
You will probably need to set PIXELS_PER_INCH for the backend you are
using to be correct for your display. This is a parameter the
respective backend files, eg, in matplotlib/backends/backend_gtk.py.
For backend_agg, you will have to change it both in
src/_backend_agg.cpp and matplotlib/backends/backend_agg.py. This is
something I would like to rationalize and perhaps move to the rc file.
I suggest setting it to your display width / pixels width, eg, 116 in
your example. Then

  figure( (8,6), dpi=116)

should produce a an 8 inch by 6 inch figure. Let me know. Then
default dpi can be set in the rc file.

None of this matters, of course, for PS, which is resolution
independent.

dpi is not really suitably named because of this additional parameter
PIXELS_PER_INCH. dpi is really a resolution parameter. When you
increase dpi, the relative sizes of everything in your image should
increase proportionately (line widths, text sizes, etc) but you have
more pixels of resolution. When you increase figure size for a give
dpi, everything should appear smaller because the physical size of the
objects in your canvas haven't changed, but your canvas has increased.

I'm open to suggestions on how to make this better.

JDH

It seems to me, from the user's point of view, that the DPI is a rendering
option, not a plotting option. I should be able to take the same plot:

p = plot(sin(x))

and render it to screen

show(p, dpi=96, size=(8, 6))

OR

show(p, pixelsize=(768, 576))

or render it for printing:

savefig('p.png', dpi=300, size=(6, 4))

OR

savefig('p.png', pixelsize=(1800, 1200))

OR

savefig('p.eps', size=(6, 4))

I think people are going to want different DPI settings for screen vs.
printing. So perhaps dpi should be an option to show() and savefig()
rather than to plot?

And rather than having different DPI defaults for each backend, I would
have thought it better to have two global default DPI settings, one for
the screen and one for the printer. You would also want two default plot
sizes in inches.

In a sane world you wouldn't need to set the DPI for the screen, you could
trust X or Windows to provide it, but in practice what X says isn't always
useful.

You might even consider adding a print() command that renders a plot with
the default printing settings to a file (or even straight to the
printer?). Perhaps savefig() should use the default printing settings when
exporting an .eps file? (Although the DPI is ignored the plot size is
still relevant.)

I hope you find these ponderings useful. I am still a bit ignorant about
aspects of matplotlib so I'll hope you'll excuse me for that.

Cheers,
Matthew.

···

On Mon, 8 Mar 2004, John Hunter wrote:

None of this matters, of course, for PS, which is resolution
independent.

dpi is not really suitably named because of this additional parameter
PIXELS_PER_INCH. dpi is really a resolution parameter. When you
increase dpi, the relative sizes of everything in your image should
increase proportionately (line widths, text sizes, etc) but you have
more pixels of resolution. When you increase figure size for a give
dpi, everything should appear smaller because the physical size of the
objects in your canvas haven't changed, but your canvas has increased.

I'm open to suggestions on how to make this better.

JDH