user12969777
user12969777

Reputation: 73

Plotting CSV file with gnuplot returning line 0: x range is invalid

My CSV file looks like this:

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

I'm running the command:

gnuplot -p -e "set datafile separator ','; plot '/temp_files/iMiHRlrcQLwWYXjbjmTydBITw_PlotGraph.csv' using 1:2 with lines;"

And I'm getting the error:

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

I've tried the following:

However, regardless of the research I'm still expecting gnuplot to accept the CSV file and return a plotted graph, how can I turn the CSV presented into a graph using gnuplot successfully?

An example of what I would want would be something along the lines of:

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

Upvotes: 0

Views: 403

Answers (2)

theozh
theozh

Reputation: 26200

As Ethan already mentioned, you need a x-coordinate. In your modified question you specify that the text in column 1 should be on the x-axis. In this case you can use the pseudocolumn 0 (which is basically the row index, starting from 0) as x-value and add the text via xticlabels(). Check help pseudocolumns and help xticlabels. For this type of plot you might want to use the plotting style with boxes or as you intended with lines.

In short, something like: plot "myData.dat" u 0:2:xtic(1) w lines, or as a full script...

Script:

### 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

Result:

enter image description here

Upvotes: 1

Ethan
Ethan

Reputation: 15143

Column 1 of your data file contains text rather than numbers. You cannot use this column as either an x or a y coordinate. Thus both plot ... using 1:2 and plot ... using 0:1 will fail because the program finds no [x,y] coordinate pair on any line of the file. That is what the error message "no valid points" is trying to tell you.

What coordinates do you want on the x and y axes of your graph? If column 2 is y, what is x?

Upvotes: 0

Related Questions