我如何绘制一个 csv 中的每个第 n 个数据点,它都是一行

How do I plot every nth datapoint in a csv that is all a single row

我的任务是绘制一些明显厌恶 newlines/columns 的人生成的数据。

我有一个格式如下的文件:

i0,x0,y0,i1,x1,y2,i2,x2,y2,i3,x3,y3,...in,xn,yn

我需要绘制 i 与 y 的关系图。

我遇到了 "every" 命令,但这似乎是为了跳过带列的数据中的行。

我 运行 在 gnuplot 4.6 Windows 7. 这只能在 gnuplot 中完成吗?如果不是,插入换行符的最佳方法是什么。我可以跳上一个 Linux 框但是这样做但是它没有可用的 gnuplot。无论哪种方式,我都更喜欢一个独立的 plt 文件,因为它会再次出现。

是的,您可以绘制这些数据,但这需要一些技巧,因为 gnuplot 通常是逐行读取数据。

您必须使用 matrix 读取数据,从第 0 列开始,每隔三列保存一次值,然后在读入 y 值时将此保存的值用作 x 值(列数模 3 == 2):

set datafile separator ','
x = 0
plot 'test.dat' matrix using (int() % 3 == 0 ? x =  : x = x, (int() % 3 == 2 ? x : 1/0)):(int() % 3 == 2 ?  : 1/0) w lp ps 2 pt 7 

有测试数据

0.1,2,3,0.2,5,6,0.4,8,9,0.8,11,12,1.6,14,15,3.2,17,18

我明白剧情了

请注意,您只能使用 gnuplot 5.0 版获得线图。在 4.6 中,1/0 导致线条被打断,您只能看到点。

对于以前的版本,您必须先将数据绘制到中间文件中,然后使用常规绘图命令再次绘制:

set datafile separator ','
x = 0
set table 'test.tab'
plot 'test.dat' matrix using (int() % 3 == 0 ? x =  : x = x, (int() % 3 == 2 ? x : 1/0)):(int() % 3 == 2 ?  : 1/0) w lp ps 2 pt 7 
unset table

set datafile separator white
plot 'test.tab' using 1:2 every 3::2 w lp ps 2 pt 7