plot resolution discrepancy with embedding in gtk

Please note that my original posting was to matplotlib-users-admin by
mistake, so not everyone saw the first part of this (below).

Based on John's suggestions, I checked figsize and dpi settings and
still find a difference in the plot quality between using pylab.figure
and using matplotlib.figure.Figure.

As a simple test, I modified the example pythonic_matplotlib.py to plot
in a gtk window and use Figure as follows:

···

----------
from pylab import figure, close, axes, subplot, show
from matplotlib.numerix import arange, sin, pi

import pygtk
pygtk.require("2.0")
import os, gtk
import matplotlib
matplotlib.use('GTKAgg')

from matplotlib.backends.backend_gtkagg import FigureCanvasGTK as
FigureCanvas
from matplotlib.figure import Figure

t = arange(0.0, 1.0, 0.01)

#fig = figure(1)
fig = Figure(dpi=100)

ax1 = fig.add_subplot(211)
ax1.plot(t, sin(2*pi*t),antialiased=True,linewidth=0.5)
ax1.grid(True)
ax1.set_ylim( (-2,2) )
ax1.set_ylabel('1 Hz')
ax1.set_title('A sine wave or two')

for label in ax1.get_xticklabels():
    label.set_color('r')

ax2 = fig.add_subplot(212)
ax2.plot(t, sin(2*2*pi*t),antialiased=True,linewidth=0.5)
ax2.grid(True)
ax2.set_ylim( (-2,2) )
l = ax2.set_xlabel('Hi mom')
l.set_color('g')
l.set_fontsize('large')

win = gtk.Window()
win.set_default_size(800,600)
win.set_title("Plotting in a GTK Window")
win.connect("destroy", lambda x: gtk.main_quit())
vbox = gtk.VBox()
canvas = FigureCanvas(fig)

vbox.pack_start(canvas)
win.add(vbox)
win.show_all()
gtk.main()

#show()
-------------

With dpi=100 (the value in my .matplotlibrc),
win.set_default_size(800,600) makes the size consistent with
'figure.figsize : 8, 6 ' in my .matplotlibrc and the plots are indeed
the same size. Note I also explicitly set antialiased=True and
linewidth=0.5 in the plot method calls to be consistent with my rc file.

Compared to the original example, with embedding the sine waves plot
jaggy, the border around the plot is not as bold, and the text is
(slightly) bigger. Am I hallucinating or is there something else
affecting the plot attributes? Thanks for any feedback.

Jeff Orrey

-----Original Message-----
From: John Hunter [mailto:jdhunter@…4…]
Sent: Tuesday, April 26, 2005 9:21 AM
To: Jeffrey Orrey
Cc: Jeff Whitaker; matplotlib-users-admin@lists.sourceforge.net
Subject: Re: plot resolution discrepancy when embedding basemap in gtk

    > Hi all, I'm embedding a map in a gtk window using Jeff
    > Whitaker's nice Basemap package. The map is not as crisp
    > when embedding it as it is when simply rendering into a
    > figure() using the matplotlib gtkagg backend. It appears
    > as if a discretization problem is making lines,
    > especially fine dotted ones, much coarser in the gtk
    > window.

    > Has anyone encountered such a resolution discrepancy when
    > plotting in a gtk window versus simply using figure()?
    > I'm using matplotlib 0.80 and basemap 0.3.1 on Linux with
    > Python 2.3.4.

All figure does in the gtkagg backend is embed the agg image in a gtk
window, just as you are doing. The only possible cause for the problem
you report is that figure respects the figsize and dpi rc settings and
so may be making the figure bigger, eg higher resolution.

Try tweaking the Figure dpi and figsize settings, and make sure you
choose win.set_default_size intelligently. Here is how the gtk figure
manager does it

        w = int (self.canvas.figure.bbox.width())
        h = int (self.canvas.figure.bbox.height())
        self.window.set_default_size (w, h)

Note also, there is an error here

  from pylab import figure
  from matplotlib.backends.backend_gtkagg import FigureCanvasGTK as
FigureCanvas

Do not import pylab if you are using the object interface. Use
matplotlib.figure.Figure instead of pylab.figure.

Don't do this either:

  from pylab import *

See http://matplotlib.sourceforge.net/faq.html#OO

Hope this helps,
JDH