如何使用 Tcl/Tk 在画布中绘制 x 轴

编程入门 行业动态 更新时间:2024-10-27 06:23:49
本文介绍了如何使用 Tcl/Tk 在画布中绘制 x 轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-05-01 09:04:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1406726.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:画布   如何使用   Tcl   Tk

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!