1

I have data which looks like this:

label1: <set of increasing numbers 1..500>
label2: <set of increasing numbers 1..500>

etc

I would like to make a picture out of that would look something like:

label1    ...           ...............         .... .   . 
label2      ................           .............. 
etc

           1 2 3 ...                                       500

Can this be done with gnuplot in some relatively straightforward way? I can transform the data into any form easily, i just don't know what to feed into gnuplot.

7
  • 1
    it's not clear to me how your input data really looks like. Is it columns with label1 to labelN as column headers and 1s =dot and 0s =no dot in the rows of the data field? Do you want a graphical plot or some ASCII output? Commented Dec 21, 2018 at 8:46
  • uh, it didn't format correctly. Fixed. Commented Dec 21, 2018 at 13:29
  • sorry, still not clear. What do you want to have as x-axis (I assume the index from 1 to 500) and which value do you want to have plotted as y-value? A dot (or no-dot) in your schematic corresponds to what number in your data? If you are flexible in formatting your data, better format it in columns not in rows for gnuplot. Commented Dec 21, 2018 at 14:37
  • sample line is "label1 1 2 20 21 22 56 57 58 59" Commented Dec 21, 2018 at 14:40
  • do you maybe mean a heat map? gnuplot.sourceforge.net/demo_5.2/heatmaps.html Commented Dec 21, 2018 at 14:42

1 Answer 1

1

maybe, we need some visual example here to find out what you really want. The follwing should be a copy&paste code. If you are reading your data from a file, replace $Data in the plot command by your filename, e.g. 'Data.dat'. Does this come closer what you want?

reset session

$Data <<EOD
label1  label2  label3
1   3   6
2   6   9
20  23  31
21  26  34
22  25  29
56  50  44
57  58  55
58  60  70
59  65  85
EOD

set colorsequence classic
set key top left
set yrange [0.5:3.5]
plot for [i=1:*] $Data u i:(i):ytic(columnhead(i)) with points pointtype 7 pointsize 2 notitle

which should result in:

enter image description here

Addition: The following code is an ugly workaround to basically transpose the data with gnuplot. The plotting result should be basically the same as above, except I made the rows different in length by removing and adding some points.

### plotting rows with different length
reset session

$DataInRows <<EOD
label1  1   2   20  21  22  56  57  58  59
label2  3   6   23  26  25  50  58
label3  6   9   31  34  29  44  55  70  88  90
EOD

stats $DataInRows u 0 nooutput   # get the number of rows
RowCount = STATS_records
array Rows[RowCount]   # define an array

# put rows as string into the array
set table $Dummy
    MaxColCount = 0
    set datafile separator "\n"        # full lines 
    # get the lines into array and at the same time determine the maximum number of columns
    plot $DataInRows u (Rows[$0+1]=stringcolumn(1), \
        MaxColCount = words(Rows[$0+1]) > MaxColCount ? words(Rows[$0+1]) : MaxColCount) \
        with table 
    set datafile separator whitespace  # set back to default
unset table
print MaxColCount

set print $Data  # print into dataset
do for [j=1:MaxColCount] {
    tmp = ''
    do for [i=1:RowCount] {
        tmp = i > 1 ? tmp."\t".word(Rows[i],j) : word(Rows[i],j)
    }
    print tmp
}
set print 

set colorsequence classic
set yrange [0.5:3.5]
plot for[i=1:RowCount] $Data u i:(i):ytic(columnhead(i)) w p pt 7 ps 2 notitle
### end of code
Sign up to request clarification or add additional context in comments.

9 Comments

I want yaxis labels to be "label1", not numbers. And I want all dots corresponding to label1 to be on the same horizontal line. I guess I could just assign a unique number to each label and do that...
visually this is perfect. No way to keep this as rows instead of columns? And can you write few words explaining what i:(i):ytic() means?
gnuplot preferentially plots columns. I don't know of a good way to plot rows. You either create a cumbersome workaround with gnuplot or use an external tool to transpose your data before plotting. i:(i):ytic(columnhead(i)) means it loops the columns from 1 to 3 and plots the values from column no. i as x-value and the constant value (i) (in each iteration) as y-value and takes the columnheader of column i as yticlabel.
and if column2 has fewer values, how do i make an empty cell?
plot for [i=1:*] ... should work with gnuplot 5.2.5 for autodetection of number of columns
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.