问题描述
限时送ChatGPT账号..我想绘制一个关于时间的 x 轴,为此我有一个包含时间值的列表.是否可以在 tk 画布中显示?
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??
推荐答案
您可以轻松地在 Tk 画布中绘制图形.您只需确定您真正想要绘制的点(即组合 X 和 Y 值).改编自该页面上的代码:
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.
plotchart 包支持更复杂的绘图功能.它相当要复杂得多 开始,但建立在相同的基础上.
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.
这篇关于如何使用 Tcl/Tk 在画布中绘制 x 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论