【问题标题】:Tcl 8.4 - Plotting a bar graphTcl 8.4 - 绘制条形图
【发布时间】:2017-03-10 17:34:53
【问题描述】:

我想创建一个包含 5 行 2 列的表格的直方图(看起来更像条形图),每列是 x 轴和 y 轴。

我是 TCL 的新手,在这里发帖之前我已经尝试了多种方法!我发现有一个叫做 plot chart 的包,从 wiki 下载并尝试了!

#! /bin/env tclsh
lappend auto_path /u/vbhaskar/work/proj2/ECE_x81_PROJECT_2
package require plotchart
canvas .c -background white -width 400 -height 200
pack   .c -fill both
#
# Create the plot with its x- and y-axes
#
set s [::Plotchart::createXYPlot .c {0.0 100.0 10.0} {0.0 100.0 20.0}]
foreach {x y} {0.0 32.0 10.0 50.0 25.0 60.0 78.0 11.0 } {
    $s plot series1 $x $y
}
$s title "Data series"
exit 0

试过上面的代码,没完全看懂不过更好。

我收到错误消息说找不到包。

在 Tcl 8.4 版本中是否有一种简单的方法可以实现我的功能?我在 Synopsys DC shell 中做 source <file_name.tcl>

【问题讨论】:

    标签: tcl


    【解决方案1】:

    我不会使用任何库,而是一些简单的代码。

    set mylist [list 0 1 2 8 3 9 4 2 5 19 6 12]
    array set arr $mylist
    
    #parray arr
    
    foreach element [array names arr] {
        puts -nonewline "x($element) "
        for {set i 0} {$i <= $arr($element)} {incr i} {
            puts -nonewline "-"
        }
        puts -nonewline "$arr($element)"
        puts "\n"
    }
    

    检查o/p:

    x(4) ---2
    
    x(0) --1
    
    x(5) --------------------19
    
    x(6) -------------12
    
    x(2) ---------8
    
    x(3) ----------9
    

    希望对你有帮助。

    【讨论】:

    • 谢谢博多洛伊!它有帮助!
    猜你喜欢
    • 2020-06-23
    • 1970-01-01
    • 2012-09-17
    • 2014-08-22
    • 2020-07-22
    • 2021-12-27
    相关资源
    最近更新 更多