How to draw x axis in a canvas using Tcl/Tk

不打扰是莪最后的温柔 提交于 2019-12-25 02:44:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!