使用gnuplot绘制CSV文件并返回第0行:x范围无效

y0u0uwnf  于 2022-12-15  发布在  其他
关注(0)|答案(2)|浏览(182)

我的CSV文件如下所示:

Sections,Score
text,5.80653548846
rdata,3.96936179484
data,0.378703493488
pdata,1.97732827586
rsrc,2.81352566021
reloc,0.46347168954

我正在运行命令:
gnuplot -p -e "set datafile separator ','; plot '/temp_files/iMiHRlrcQLwWYXjbjmTydBITw_PlotGraph.csv' using 1:2 with lines;"
我得到了错误:

line 0: warning: Skipping data file with no valid points

set datafile separator ','; plot '/temp_files/iMiHRlrcQLwWYXjbjmTydBITw_PlotGraph.csv' using 1:2 with lines;
                                                                                                                                                ^
line 0: x range is invalid

我尝试了以下方法:

  • 编辑CSV文件,使其不包含Sections,Score部件。
  • 使用set xlabel "Sections"; set ylabel "Scores";设置ylabel和xlabel
  • 运行set title "Entropy"; set grid; plot "FILENAME"; using 0:1 with lines
  • 使用这些帖子中的建议:1234

然而,不管我做了什么研究,我仍然期望gnuplot接受CSV文件并返回一个绘制的图形,我如何才能成功地使用gnuplot将显示的CSV转换成图形呢?
我想要的一个例子是沿着如下的东西:

8
    7
 S  6
 C  5
 O  4
 R  3 |\        ___
 E  2 | \      /
    1 |  \____/
    0 |  
     text rdata data
         Sections
roejwanj

roejwanj1#

正如Ethan已经提到的,您需要一个x坐标。在修改后的问题中,您指定列1中的文本应该在x轴上。在这种情况下,您可以使用伪列0(其基本上是行索引,从0开始)作为x值,并通过xticlabels()添加文本。检查help pseudocolumnshelp xticlabels。对于这种类型的打印,可能需要使用打印样式with boxes或所需的with lines
简而言之,类似于:plot "myData.dat" u 0:2:xtic(1) w lines,或作为完整脚本...

脚本:

### plot "text" data
reset session

$Data <<EOD
Sections,Score
text,5.80653548846
rdata,3.96936179484
data,0.378703493488
pdata,1.97732827586
rsrc,2.81352566021
reloc,0.46347168954
EOD

set datafile separator comma
set style fill solid 0.3
set boxwidth 0.8
set xtics out nomirror
set grid y
set xlabel "Sections"
set ylabel "Score"
set key noautotitle

plot $Data u 0:2:xtic(1) w boxes, \
        '' u 0:2 w linespoints pt 7
### end of script

结果:

fumotvh3

fumotvh32#

数据文件的第1列包含文本而不是数字。您不能将此列用作x或y坐标。因此,plot ... using 1:2plot ... using 0:1都将失败,因为程序在文件的任何一行都找不到[x,y]坐标对。这就是错误消息"no valid points"试图告诉您的。
在图表的x轴和y轴上,您需要什么样的坐标?如果第2列是y,那么x是什么?

相关问题