简体   繁体   English

Gnuplot CSV - 不同格式的数据

[英]Gnuplot CSV - Data in a different format

I have a CSV file with data in this format:我有一个包含以下格式数据的 CSV 文件:

Category        X-Axis  Y-Axis
Cat1            100     10.1
Cat1            101     10.12
Cat1            102     8.12

Cat2            100     11.1
Cat2            101     11.31
Cat2            102     12.11

Cat3            100     13.1

I would like to generate line graph using GNUplot, but GNUplot seems draw graph correctly only when data is cross-tabbed like this:我想使用 GNUplot 生成折线图,但 GNUplot 似乎只有在数据像这样交叉表时才能正确绘制图形:

X-Axis      Cat1        Cat2        Cat3
100         10.1        11.1        13.1
101         10.12       11.31       13.2
102         8.12        12.11       13.3

The number of categories are not fixed, cross-tabbing will result in way too many categories will null/zero values.类别的数量不固定,交叉表将导致太多类别将空/零值。

Any suggestion to have GNUPlot draw line graphs without cross-tabbing data?有没有建议让 GNUPlot 在没有交叉表数据的情况下绘制折线图?

Make sure to separate each category by 2 or more blank lines.确保用 2 个或更多空行分隔每个类别。

Then plot with然后用

plot "gnuplot.dat"  using 2:3:(column(-2)) linecolor variable with lines

This uses columns 2 and 3 for x, y respectively and the pseudo-column (column(-2)) .这将分别使用第 2 列和第 3 列作为 x、y 和伪列(column(-2)) This is actually a reference to the distinct, internal index gnuplot gives to each data set.这实际上是对 gnuplot 为每个数据集提供的不同内部索引的引用。

You may want to check the detailed gnuplot help pages: within gnuplot enter help plot index .您可能需要查看详细的 gnuplot 帮助页面:在 gnuplot 中输入help plot index

If what you want is a distinct line with key/legend for each of your categories:如果您想要的是每个类别的带有键/图例的不同行:

plot for [i=1:no_categories] datafile index i using 2:3 title "Cat".i

(make sure you have two empty lines between datasets, or use every ) (确保数据集之间有两个空行,或使用every

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM