473,695 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Matplotlib and the Tk-Backend

Hi everyone,

I'm new here and I have a question ( I guess as everybody who is new
here ;-) ),

I'm having some strange problem with Matplotlib, using it in a Tkinter
application.

I create a Canvas, a figure, subplot and then a toolbar. It works
fine, but only without the toolbar! When I want to add the toolbar, I
get an error

File "./tkViewer.py", line 102, in setupGUI
self.toolbar = NavigationToolb ar2TkAgg( self.canvas, master )
File "/usr/lib/python2.4/site-packages/matplotlib/backends/
backend_tkagg.p y", line 537, in __init__
NavigationToolb ar2.__init__(se lf, canvas)
File "/usr/lib/python2.4/site-packages/matplotlib/backend_bases.p y",
line 1107, in __init__
self._init_tool bar()
File "/usr/lib/python2.4/site-packages/matplotlib/backends/
backend_tkagg.p y", line 577, in _init_toolbar
borderwidth=2)
File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 2378, in __init__
Widget.__init__ (self, master, 'frame', cnf, {}, extra)
File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1865, in __init__
self.tk.call(
_tkinter.TclErr or: bad screen distance "500.0"

Here is the part my code:

self.canvFrame = Frame(master)
self.canvFrame. pack(side=TOP, fill=BOTH, expand=1)
self.canvFrame2 = Frame(self.canv Frame)
self.canvFrame2 .pack(side=LEFT , fill=BOTH, expand=1)
self.f = Figure(figsize= (5,4), dpi=100)
self.a = self.f.add_subp lot(111)
self.subplAxis = self.f.get_axes ()
self.canvas = FigureCanvasTkA gg(self.f,
master=self.can vFrame2)
self.canvas.sho w()
self.canvas.get _tk_widget().pa ck(side=TOP, fill=BOTH,
expand=1)
self.toolbar = NavigationToolb ar2TkAgg( self.canvas,
self.canvFrame2 )
self.toolbar.up date()
self.canvas._tk canvas.pack(sid e=TOP, fill=X, expand=1)
master is a parameter passed to my method, which actually is set to
Tk()

What did I get wrong? What is the problem? Thanks in advance...

Thorsten

Apr 26 '07 #1
1 3860
thorstenkranz wrote:
Hi everyone,

I'm new here and I have a question ( I guess as everybody who is new
here ;-) ),

I'm having some strange problem with Matplotlib, using it in a Tkinter
application.

I create a Canvas, a figure, subplot and then a toolbar. It works
fine, but only without the toolbar! When I want to add the toolbar, I
get an error

File "./tkViewer.py", line 102, in setupGUI
self.toolbar = NavigationToolb ar2TkAgg( self.canvas, master )
File "/usr/lib/python2.4/site-packages/matplotlib/backends/
backend_tkagg.p y", line 537, in __init__
NavigationToolb ar2.__init__(se lf, canvas)
File "/usr/lib/python2.4/site-packages/matplotlib/backend_bases.p y",
line 1107, in __init__
self._init_tool bar()
File "/usr/lib/python2.4/site-packages/matplotlib/backends/
backend_tkagg.p y", line 577, in _init_toolbar
borderwidth=2)
File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 2378, in __init__
Widget.__init__ (self, master, 'frame', cnf, {}, extra)
File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1865, in __init__
self.tk.call(
_tkinter.TclErr or: bad screen distance "500.0"

Here is the part my code:

self.canvFrame = Frame(master)
self.canvFrame. pack(side=TOP, fill=BOTH, expand=1)
self.canvFrame2 = Frame(self.canv Frame)
self.canvFrame2 .pack(side=LEFT , fill=BOTH, expand=1)
self.f = Figure(figsize= (5,4), dpi=100)
self.a = self.f.add_subp lot(111)
self.subplAxis = self.f.get_axes ()
self.canvas = FigureCanvasTkA gg(self.f,
master=self.can vFrame2)
self.canvas.sho w()
self.canvas.get _tk_widget().pa ck(side=TOP, fill=BOTH,
expand=1)
self.toolbar = NavigationToolb ar2TkAgg( self.canvas,
self.canvFrame2 )
self.toolbar.up date()
self.canvas._tk canvas.pack(sid e=TOP, fill=X, expand=1)
master is a parameter passed to my method, which actually is set to
Tk()

What did I get wrong? What is the problem? Thanks in advance...

Thorsten
Just prior to "self.toolb ar = ...", try :

master.winfo_to plevel().update _idletasks()

James
Apr 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2614
by: John Hunter | last post by:
matplotlib is a 2D plotting library for python. You can use matplotlib interactively from a python shell or IDE, or embed it in GUI applications (WX, GTK, and Tkinter). matplotlib supports many plot types: line plots, bar charts, log plots, images, pseudocolor plots, legends, date plots, finance charts and more. What's new since matplotlib 0.50 This is the first wide release in 5 months and there has been a tremendous amount of...
1
2695
by: jean.rossier | last post by:
Hello All, I am facing a problem while importing pylab library(in a .py program file) via web browser however the same program works when I execute it from the command prompt. my configuration : Fedora Core 3 Apache 2.0
4
2249
by: Matt Feinstein | last post by:
Hi all-- I'm planning to try to do a completely local install of matplotlib (in Fedora Core 1)-- the system administrator isn't going to stop me-- but he isn't going to cooperate either. I've got the tarballs for python, numeric, numarray, matplotlib, ipython, wxpython and freetype-- which I think covers the various pre-requisites and post-requisites. One semi-obvious question is where to put the freetype library (the system version in...
0
1568
by: sturlamolden | last post by:
Recently, I have been trying to test Python as an alternative to Matlab. I have problems getting matplotlib to work on Windows (ActivePython 2.4.2). After installing the precompiled binary packages for NumPy 0.9.5 and Matplotlib 0.87.1, I get this error message: >>> import pylab as p Traceback (most recent call last): File "<pyshell#4>", line 1, in ? import pylab as p File "C:\Python24\Lib\site-packages\pylab.py", line 1, in ?
0
2593
by: spross | last post by:
hi all i have to use matplotlib on mac os x. on the official site of matplotlib, i found a link to precompiled python packages for mac os x: http://pythonmac.org/packages/py24-fat/index.html so first, i installed python 2.4. that works great! if i type 'python' in the terminal, it loads python 2.4. after that, i loaded and installed the matplotlib package from this
1
6093
by: 3056kgw | last post by:
I'm fairly new to programming GUI's and I'm trying to control the zoom of a figure from matplotlib using a scrollbar. I can create the canvas for the figure with... import matplotlib import Tkinter as Tk from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg ... root = Tk.Tk() ... canvas = FigureCanvasTkAgg(f, master=root)
12
3429
by: orangeDinosaur | last post by:
Hi, I am exploring the possibility of using python as a replacement of MATLAB when I leave school. So, I've been playing with matplotlib and have run into some weird behavior after recently installing python 2.5.1 and matplotlib 0.90 on my Windows XP machine. Here's an example of what I see:
0
1934
by: Soren | last post by:
Hi, I'm trying to create a small GUI program where I can do plots using Matplotlib. I've been trying to borrow code from the examples at the matplotlib website, but I can't get it to work. I want to be able to create a wx.Panel that contains an axis for plotting. Around it i want other panels containing various settings, buttons etc. to control the plot. So far I can't even get the program to actually show a plot in a panel.
3
4716
by: vajratkarviraj | last post by:
i hav python2.5, matplotlib0.90.1, and py2exe for python 2.5 all on windows xp... i hav a python program(letsc.py) which uses the matplotlib package... and i want 2 make an exe of it for distribution on other comps... i used py2exe... i wrote a setup.py whose contents are : from distutils.core import setup import py2exe import matplotlib setup(console=, options={ 'py2exe': { 'packages' : ,
1
4596
by: Czenek | last post by:
Hi, can I use somehow standard matplotlib's functions pan/zoom? I would like to zoom my created graph after double-clicking and move with it after keyboard (arrow) pressing (similar as Google Maps). And I want also to control how much it zooms and how far is the graph moved after pressing a key (or double-clicking). So are there any appropriate API functions which can be connected with keyboard and mouse events? Thanks
0
8623
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9113
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8977
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6488
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5837
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.