Kamil Gosciminski
Kamil Gosciminski

Reputation: 17177

GnuPlot chart drawing for each text file

I compare four kind of sorting algorithms, and their inversions and comparisions for each algorithm are stored in a file. What I need now is to draw a scatter with markers (x,y) for each file where

x -> number of inversions
y -> number of comparisions

and scale it to the numbers, so for example we have IS10.txt which stands for InsertionSort and it has 300 lines with x's and y's.

Sample data

line 1: 20 33
line 2: 18 27
...
line 300: 21 24

The key is to be able to generate diagrams for comparison.

Upvotes: 0

Views: 579

Answers (1)

Christoph
Christoph

Reputation: 48430

Plotting a single file is straightforward, just use

plot 'IS10.txt' using 1:2 title 'InsertionSort'

If you want to plot all files, you can do it as follows:

list = system('ls -1 *.txt | tr "\n" " "')
set key out
plot for [file in list] file using 1:2 title file

Here, I assumed, that all .txt files in the current directory should be plotted. You could of course also generate the list manually. It should contain all file names, delimited by a space (e.g. list = "IS10.txt HS10.txt ...").

That plots all data points of one file with the same linetype. The first file uses linetype 1, the second one linetype 2 etc. Type test to see how the points and colors of these default linetype look like.

You can use something like set linetype 1 linecolor rgb 'blue' pointtype 7 to change these settings in order to get 20 well-distinguishable point styles.

Upvotes: 1

Related Questions