matplotlib with tk? online examples fail...

I'm quite new to python, but am attempting to add basic plotting
functionality to a tk-based GUI application that is run primarily on a
Mac. My initial attempts at simply calling "plot" or "errorbar" from
within the application resulted in erratic behavior on Python
installed through macports on my machine with OSX 10.5 (the plot
appears, but the window is unresponsive), or no plot whatsoever (on a
friend's Mac with OSX 10.6 and Python, Numpy, and Matplotlib installed
through their "official" .dmg packages). All versions are current
(Python 2.6.2, Matplotlib 0.99.1.1).

When looking at the matplotlib website, I attempted to run the
following examples:

http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk.py
http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk2.py

...but these fail on my machine (OSX 10.5):

···

----------

udp009069uds:fret_analysis jshine$ python embedding_in_tk.py
Traceback (most recent call last):
  File "embedding_in_tk.py", line 6, in <module>
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2TkAgg
  File "/Users/jshine/Documents/root/matplotlib/lib/python/matplotlib/backends/backend_tkagg.py",
line 8, in <module>
    import tkagg # Paint image to Tk photo blitter extension
  File "/Users/jshine/Documents/root/matplotlib/lib/python/matplotlib/backends/tkagg.py",
line 1, in <module>
    import _tkagg
ImportError: No module named _tkagg
udp009069uds:fret_analysis jshine$

----------

For those familiar with macports, I did install it with the "tkinter"
option enabled:

----------

dp009069uds:fret_analysis jshine$ port info py26-matplotlib
py26-matplotlib @0.99.1.1 (python, graphics, math)
Variants: cairo, darwin_8, ghostscript, gtk2, latex, qt4,
[+]tkinter, wxpython

Description: Matplotlib is a pure python plotting library
with the goal of making publication quality plots using a syntax
familiar to matlab
                      users. The library uses numpy for handling large
data sets and supports a variety of output backends. This port
provides variants for
                      the different GUIs (gtk2, tkinter, wxpython).
Homepage: http://matplotlib.sourceforge.net

Library Dependencies: python26, freetype, libpng, py26-dateutil,
py26-tz, py26-numpy, py26-configobj, py26-pyobjc2, py26-pyobjc2-cocoa
Platforms: darwin
License: unknown
Maintainers: ram@...1611..., openmaintainer@...1611...
udp009069uds:fret_analysis jshine$

----------

...so at this point, I'm pretty much stuck -- my own application
doesn't work, and I don't have a working example to follow. I'd
greatly appreciate any pointers!

Thanks,
Jon

--
Jonathan Tomshine, PhD
University of California, San Francisco
Genentech Hall
600 16th St.
San Francisco, CA 94158-2140
jtomshine@...287...

Jonathan Tomshine wrote:

I'm quite new to python, but am attempting to add basic plotting
functionality to a tk-based GUI application that is run primarily on a
Mac. My initial attempts at simply calling "plot" or "errorbar" from
within the application resulted in erratic behavior on Python
installed through macports on my machine with OSX 10.5 (the plot
appears, but the window is unresponsive), or no plot whatsoever (on a
friend's Mac with OSX 10.6 and Python, Numpy, and Matplotlib installed
through their "official" .dmg packages). All versions are current
(Python 2.6.2, Matplotlib 0.99.1.1).

When looking at the matplotlib website, I attempted to run the
following examples:

http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk.py
http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk2.py

...but these fail on my machine (OSX 10.5):
  ----------

udp009069uds:fret_analysis jshine$ python embedding_in_tk.py
Traceback (most recent call last):
  File "embedding_in_tk.py", line 6, in <module>
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2TkAgg
  File "/Users/jshine/Documents/root/matplotlib/lib/python/matplotlib/backends/backend_tkagg.py",
line 8, in <module>
    import tkagg # Paint image to Tk photo blitter extension
  File "/Users/jshine/Documents/root/matplotlib/lib/python/matplotlib/backends/tkagg.py",
line 1, in <module>
    import _tkagg
ImportError: No module named _tkagg
udp009069uds:fret_analysis jshine$
  
Jonathan: You say you're using macports matplotlib, but that traceback does not point to a macports directory (which should be in /opt/local). Perhaps you have PYTHONPATH set so you're picking up a local installation of matplotlib, which was not built with tkagg support?

-Jeff

···

----------

For those familiar with macports, I did install it with the "tkinter"
option enabled:

----------

dp009069uds:fret_analysis jshine$ port info py26-matplotlib
py26-matplotlib @0.99.1.1 (python, graphics, math)
Variants: cairo, darwin_8, ghostscript, gtk2, latex, qt4,
[+]tkinter, wxpython

Description: Matplotlib is a pure python plotting library
with the goal of making publication quality plots using a syntax
familiar to matlab
                      users. The library uses numpy for handling large
data sets and supports a variety of output backends. This port
provides variants for
                      the different GUIs (gtk2, tkinter, wxpython).
Homepage: http://matplotlib.sourceforge.net

Library Dependencies: python26, freetype, libpng, py26-dateutil,
py26-tz, py26-numpy, py26-configobj, py26-pyobjc2, py26-pyobjc2-cocoa
Platforms: darwin
License: unknown
Maintainers: ram@...1611..., openmaintainer@...1611...
udp009069uds:fret_analysis jshine$

----------

...so at this point, I'm pretty much stuck -- my own application
doesn't work, and I don't have a working example to follow. I'd
greatly appreciate any pointers!

Thanks,
Jon

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : Jeffrey S. Whitaker: NOAA Physical Sciences Laboratory

You're right! I almost forgot that I had installed a local copy of
matplotlib a long time ago. It looks like Python was finding that
copy before it found the "correct" one. The example appears to work
now.

Thanks again,
-Jon

···

On Fri, Sep 25, 2009 at 2:14 PM, Jeff Whitaker <jswhit@...146...> wrote:

Jonathan Tomshine wrote:

I'm quite new to python, but am attempting to add basic plotting
functionality to a tk-based GUI application that is run primarily on a
Mac. My initial attempts at simply calling "plot" or "errorbar" from
within the application resulted in erratic behavior on Python
installed through macports on my machine with OSX 10.5 (the plot
appears, but the window is unresponsive), or no plot whatsoever (on a
friend's Mac with OSX 10.6 and Python, Numpy, and Matplotlib installed
through their "official" .dmg packages). All versions are current
(Python 2.6.2, Matplotlib 0.99.1.1).

When looking at the matplotlib website, I attempted to run the
following examples:

http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk.py

http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk2.py

...but these fail on my machine (OSX 10.5):
----------

udp009069uds:fret_analysis jshine$ python embedding_in_tk.py
Traceback (most recent call last):
File "embedding_in_tk.py", line 6, in <module>
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2TkAgg
File
"/Users/jshine/Documents/root/matplotlib/lib/python/matplotlib/backends/backend_tkagg.py",
line 8, in <module>
import tkagg # Paint image to Tk photo blitter
extension
File
"/Users/jshine/Documents/root/matplotlib/lib/python/matplotlib/backends/tkagg.py",
line 1, in <module>
import _tkagg
ImportError: No module named _tkagg
udp009069uds:fret_analysis jshine$

Jonathan: You say you're using macports matplotlib, but that traceback does
not point to a macports directory (which should be in /opt/local). Perhaps
you have PYTHONPATH set so you're picking up a local installation of
matplotlib, which was not built with tkagg support?

-Jeff

----------

For those familiar with macports, I did install it with the "tkinter"
option enabled:

----------

dp009069uds:fret_analysis jshine$ port info py26-matplotlib
py26-matplotlib @0.99.1.1 (python, graphics, math)
Variants: cairo, darwin_8, ghostscript, gtk2, latex, qt4,
[+]tkinter, wxpython

Description: Matplotlib is a pure python plotting library
with the goal of making publication quality plots using a syntax
familiar to matlab
users. The library uses numpy for handling large
data sets and supports a variety of output backends. This port
provides variants for
the different GUIs (gtk2, tkinter, wxpython).
Homepage: http://matplotlib.sourceforge.net

Library Dependencies: python26, freetype, libpng, py26-dateutil,
py26-tz, py26-numpy, py26-configobj, py26-pyobjc2, py26-pyobjc2-cocoa
Platforms: darwin
License: unknown
Maintainers: ram@...1611..., openmaintainer@...1611...
udp009069uds:fret_analysis jshine$

----------

...so at this point, I'm pretty much stuck -- my own application
doesn't work, and I don't have a working example to follow. I'd
greatly appreciate any pointers!

Thanks,
Jon

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...2583...9...
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : Jeffrey S. Whitaker: NOAA Physical Sciences Laboratory

--
Jonathan Tomshine, PhD
University of California, San Francisco
Genentech Hall
600 16th St.
San Francisco, CA 94158-2140
jtomshine@...287...