【问题标题】:plotting matrix-like data as points将类似矩阵的数据绘制为点
【发布时间】:2018-12-21 05:56:17
【问题描述】:

我的数据如下所示:

label1: <set of increasing numbers 1..500>
label2: <set of increasing numbers 1..500>

我想用它制作一张看起来像这样的图片:

label1    ...           ...............         .... .   . 
label2      ................           .............. 
etc

           1 2 3 ...                                       500

这可以用 gnuplot 以某种相对简单的方式完成吗? 我可以轻松地将数据转换为任何形式,我只是不知道向 gnuplot 输入什么。

【问题讨论】:

  • 我不清楚您的输入数据的真实情况。是label1labelN 作为列标题并且1s =dot 和0s = 在数据字段的行中没有点的列吗?你想要一个图形图还是一些 ASCII 输出?
  • 呃,它的格式不正确。固定。
  • 抱歉,还是不清楚。您希望将什么作为 x 轴(我假设索引从 1 到 500)以及您希望将哪个值绘制为 y 值?原理图中的点(或无点)对应于数据中的哪个数字?如果您可以灵活地格式化数据,最好将其格式化为列而不是行中的 gnuplot。
  • 示例行是“label1 1 2 20 21 22 56 57 58 59”

标签: gnuplot


【解决方案1】:

也许,我们需要一些视觉示例来找出您真正想要的。 以下应该是复制和粘贴代码。 如果您正在从文件中读取数据,请将plot 命令中的$Data 替换为您的文件名,例如'Data.dat'。这是否更接近您想要的?

reset session

$Data <<EOD
label1  label2  label3
1   3   6
2   6   9
20  23  31
21  26  34
22  25  29
56  50  44
57  58  55
58  60  70
59  65  85
EOD

set colorsequence classic
set key top left
set yrange [0.5:3.5]
plot for [i=1:*] $Data u i:(i):ytic(columnhead(i)) with points pointtype 7 pointsize 2 notitle

这应该导致:

补充: 下面的代码是一个丑陋的解决方法,基本上用 gnuplot 转置数据。绘制结果应该与上面基本相同,只是我通过删除和添加一些点使行的长度不同。

### plotting rows with different length
reset session

$DataInRows <<EOD
label1  1   2   20  21  22  56  57  58  59
label2  3   6   23  26  25  50  58
label3  6   9   31  34  29  44  55  70  88  90
EOD

stats $DataInRows u 0 nooutput   # get the number of rows
RowCount = STATS_records
array Rows[RowCount]   # define an array

# put rows as string into the array
set table $Dummy
    MaxColCount = 0
    set datafile separator "\n"        # full lines 
    # get the lines into array and at the same time determine the maximum number of columns
    plot $DataInRows u (Rows[$0+1]=stringcolumn(1), \
        MaxColCount = words(Rows[$0+1]) > MaxColCount ? words(Rows[$0+1]) : MaxColCount) \
        with table 
    set datafile separator whitespace  # set back to default
unset table
print MaxColCount

set print $Data  # print into dataset
do for [j=1:MaxColCount] {
    tmp = ''
    do for [i=1:RowCount] {
        tmp = i > 1 ? tmp."\t".word(Rows[i],j) : word(Rows[i],j)
    }
    print tmp
}
set print 

set colorsequence classic
set yrange [0.5:3.5]
plot for[i=1:RowCount] $Data u i:(i):ytic(columnhead(i)) w p pt 7 ps 2 notitle
### end of code

【讨论】:

  • 我希望 yaxis 标签为“label1”,而不是数字。我希望与 label1 对应的所有点都在同一水平线上。我想我可以为每个标签分配一个唯一的编号,然后这样做......
  • 视觉上这是完美的。没有办法将其保留为行而不是列?你能写几句话来解释 i:(i):ytic() 的含义吗?
  • gnuplot 优先绘制列。我不知道绘制行的好方法。您可以使用 gnuplot 创建一个繁琐的解决方法,或者使用外部工具在绘图之前转置数据。 i:(i):ytic(columnhead(i)) 表示它将列从 1 循环到 3 并绘制列号中的值。 i 作为 x 值,常数值 (i)(在每次迭代中)作为 y 值,并将列 i 的列标题作为 yticlabel。
  • 如果 column2 的值较少,我如何制作一个空单元格?
  • plot for [i=1:*] ... 应该与 gnuplot 5.2.5 一起使用以自动检测列数
猜你喜欢
  • 2019-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-27
  • 1970-01-01
相关资源
最近更新 更多