如何使用 Tcl/Tk 在画布中绘制 x 轴 [英] How to draw x axis in a canvas using Tcl/Tk

查看:35
本文介绍了如何使用 Tcl/Tk 在画布中绘制 x 轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个关于时间的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆