[Tutor] Scaling a Tkinter canvas widget

Kent Johnson kent37 at tds.net
Mon Oct 27 12:11:46 CET 2008

On Sun, Oct 26, 2008 at 10:20 PM, Mike Meisner <mikem at blazenetme.net> wrote:
> 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.
> 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).

I don't know if there is a Tkinter function for this but it will have
to do the scaling itself; ultimately the points have to be converted
to window coordinates to be drawn.

You might want to look at matplotlib, it is pretty simple to make line
and scatter plots with it.


More information about the Tutor mailing list