Search code examples
csvgnuplot

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:

  • Editing the CSV file to not contain the Sections,Score part.
  • Setting the ylabel and xlabel with set xlabel "Sections"; set ylabel "Scores";
  • Running set title "Entropy"; set grid; plot "FILENAME"; using 0:1 with lines
  • Using the suggestions from these posts: 1, 2, 3, 4

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

Solution

  • 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