如何计算Gnuplot输入文件中的索引数 [英] How to count the number of indices in a Gnuplot input file

查看:29
本文介绍了如何计算Gnuplot输入文件中的索引数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想从一个数据文件中绘图,该文件的x和y数据字段的数目不确定(长度未知但长度不变).我想将它们全部绘制在一张图上,但是要用不同的颜色.

so I want to plot from a data file which has an undetermined number of fields of x and y data (of unknown but constant length). I want to plot them all together on one graph, BUT with different colors.

在不指定索引的情况下,它们都以相同的颜色绘制.

Without specifying the index, they all plot together with the same color.

在索引上使用for循环或单独编写索引会以不同的颜色将它们绘制在一起,但是程序将不知道要循环遍历多少个索引.

Using a for-loop on the index or writing the indicies individually DOES plot them together with different colors, BUT the program will not know how many indicies to loop over.

为for循环的最大值设置一个非常高的数字,但是当数据用完时会产生错误消息.

Setting a really high number for the max of the for-loop works, but makes error messages when it runs out of data.

是否有任何方法可以处理gnuplot中的数据以得出for循环的索引数?

Is there any way to manipulate the data in gnuplot to derive the number of indices for the for-loop?

推荐答案

如果您有gnuplot> = 4.6.0,则可以使用stats命令:

If you have gnuplot >= 4.6.0, you can use the stats command:

#!/usr/bin/env gnuplot

reset

datafile = 'data.dat'

set terminal png size 600,400
set output 'test.png'

stats datafile

plot for [i=1:STATS_blocks] datafile index (i-1) pt 7 ps 2 title 'record '.i

如果您的数据看起来像这样(两个空白行分隔了数据块)

If your data looks like this (with two blank lines separating the data blocks)

1 1


2 2


3 3


4 2


0 3

该脚本将绘制此图:

对于具有多于(x,y)对的数据块也应如此.

The same should apply for blocks of data with more than one (x,y) pair.

这篇关于如何计算Gnuplot输入文件中的索引数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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