gyorgyabraham
gyorgyabraham

Reputation: 2608

Gnuplot, CSV, only distinct labels?

I need some help on processing a CSV file with gnuplot. My CSV file looks like:

a,1002
b,612
b,893
b,361
b,932
b,483
b,899
b,614
c,722
d,1038
d,1580

I want it to use the 2nd column for Y value, the line number as X value. This is done easily.

I managed to put the first column as xtics label, but after hours of Google-ing, I did not find a solution to tell gnuplot to only print a label only once (my x axis was crowded with labels, making it unreadable).

I need something like:

.
.     b
.a ***** c
.**    ***       d  ****
.        ************
........................

But I'm getting this:

    .
    .  
    .  *****
    .**     ***          ****
    .        ************
    ........................
   sdflksdjflksdjflksdjflkadjflksjdflkasj

Labels will be okay on the axis or on the graph line too, it doesn't matter.

Upvotes: 1

Views: 824

Answers (2)

chl
chl

Reputation: 29367

Some further suggestions:

set pointsize 2.5
set xtics ("a" 1, "b" 5, "c" 9, "d" 10.5)
set xrange [0:12]
plot "< cat -n aa.csv | sed -e 's/,/  /g'" using 1:3 pt 7 notitle

yields unequally spaced labels in place of x-ticks (as suggested by @choroba, which also provided a way to automate the determination of mid-interval for larger datasets). (Here aa.csv contains data as shown in your question.)

enter image description here

If you want labels to appear in the plotting region rather than under the x-axis, then you can start with

set format x ""

and then place your labels above the highest value found in any of the above categories, a, ..., d.

Upvotes: 1

choroba
choroba

Reputation: 241898

To set xtics that are not periodic, use

set xtics ("a" 1, "b" 2, "c" 9, "d" 10)

You can extract the information from your data by a simple script, e.g.

cut -f1 -d, data | while read name ; do
    let line++
    if [[ $name != $oldname ]] ; then
        oldname=$name
        echo "'$name'" $line
    fi
done

Upvotes: 2

Related Questions