473,320 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 = NavigationToolbar2TkAgg( self.canvas, master )
File "/usr/lib/python2.4/site-packages/matplotlib/backends/
backend_tkagg.py", line 537, in __init__
NavigationToolbar2.__init__(self, canvas)
File "/usr/lib/python2.4/site-packages/matplotlib/backend_bases.py",
line 1107, in __init__
self._init_toolbar()
File "/usr/lib/python2.4/site-packages/matplotlib/backends/
backend_tkagg.py", 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.TclError: 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.canvFrame)
self.canvFrame2.pack(side=LEFT, fill=BOTH, expand=1)
self.f = Figure(figsize=(5,4), dpi=100)
self.a = self.f.add_subplot(111)
self.subplAxis = self.f.get_axes()
self.canvas = FigureCanvasTkAgg(self.f,
master=self.canvFrame2)
self.canvas.show()
self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH,
expand=1)
self.toolbar = NavigationToolbar2TkAgg( self.canvas,
self.canvFrame2 )
self.toolbar.update()
self.canvas._tkcanvas.pack(side=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 3837
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 = NavigationToolbar2TkAgg( self.canvas, master )
File "/usr/lib/python2.4/site-packages/matplotlib/backends/
backend_tkagg.py", line 537, in __init__
NavigationToolbar2.__init__(self, canvas)
File "/usr/lib/python2.4/site-packages/matplotlib/backend_bases.py",
line 1107, in __init__
self._init_toolbar()
File "/usr/lib/python2.4/site-packages/matplotlib/backends/
backend_tkagg.py", 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.TclError: 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.canvFrame)
self.canvFrame2.pack(side=LEFT, fill=BOTH, expand=1)
self.f = Figure(figsize=(5,4), dpi=100)
self.a = self.f.add_subplot(111)
self.subplAxis = self.f.get_axes()
self.canvas = FigureCanvasTkAgg(self.f,
master=self.canvFrame2)
self.canvas.show()
self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH,
expand=1)
self.toolbar = NavigationToolbar2TkAgg( self.canvas,
self.canvFrame2 )
self.toolbar.update()
self.canvas._tkcanvas.pack(side=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.toolbar = ...", try :

master.winfo_toplevel().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
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...
1
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...
4
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...
0
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...
0
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 ...
1
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...
12
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...
0
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...
3
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.