问题
I wanted to plot an x-axis with respect to time ,for which i have a list which contains time values. Is it possible to display it in a tk canvas??
回答1:
You can easily plot a graph in a Tk canvas. You've just got to work out what points you really want to plot (i.e., assemble both the X and Y values). Adapted from the code on that page:
set width 100
set height 100
pack [canvas .c -width $width -height $height]
# Assuming you've got a list of points in $data
set count 0
foreach yValue $data {
lappend coords \
[expr {$width * $count/double([llength $data])}] \
[expr {$height - $yValue}]
incr count
}
.c create line $coords
Scaling the coordinates is just a matter of plugging the right code into the expressions.
More complex graphing capabilities are supported by the plotchart package. It's quite a lot more complex to start with, but is built on the same foundations.
来源:https://stackoverflow.com/questions/24863549/how-to-draw-x-axis-in-a-canvas-using-tcl-tk