[Tutor] Scaling a Tkinter canvas widget

Mike Meisner mikem at blazenetme.net
Mon Oct 27 03:20:49 CET 2008


I would like to plot various datasets on a Tkinter canvas widget.

The problem is that each of my datasets have different x,y extremes.  For instance, one dataset may have xmin = 0, xmax = 300, ymin = 0, ymax = 300;  whereas the next dataset may have xmin = -200, xmax = 1200, ymin = 2000, ymax = 5000.  I need the whole canvas area to be available for plotting each dataset consecutively - i.e., plot one dataset, capture the image, clear the canvas and plot the next dataset with a new scale, etc.

As best I can tell the Tkinter canvas widget uses two coordinate systems:  1) the canvas coordinate system in pixels that runs from (0, 0) to (xmaxpixel, ymaxpixel), and 2) a window coordinate system that allows a wider range to enable scrolling the canvas within the window coordinate system.

What I'd like to do is simply scale the canvas coordinate system to fit the x,y extents of a dataset.  I can write a function to do this but it would be costly time-wise for plotting a large dataset (to say nothing of multiple large datasets).

My documentation for Tkinter is pretty sketchy.  I was hoping there was a canvas method I could use to re-scale the canvas widget before I plot each dataset, but there's nothing apparent in my documentation.

Is there someone familiar with Tkinter that would know how to re-scale a canvas?  Or, could tell me that there is no efficient way to do this other than writing a function to re-scale for each data point?

I'm sure that there are Python add-ins that would do what I want, but this is a quick one-time project and it's not worth the time to muck around with them compared to writing a scaling function.

Thanks for your help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081026/fa29196e/attachment.htm>


More information about the Tutor mailing list