caius
caius

Reputation: 23

gnuplot: Create multiple boxplots from different data files on the same output

I have a set of files that contain data that I want to produce a set of box plots for in order to compare them. I can get the data into gnuplot, but I don't know the correct format to separate each file into its own plot.

I have tried reading all the required files into a variable, which does work, however when the plot is produced, all the boxplots are on top of each other. I need to get gnuplot to index each plot along one space for each new data file.

For example, this produces the output with overlaying plots:

FILES = system("ls -1 /path/to/files/*")

plot    for [data in FILES] data using (1):($4)  with boxplot notitle

I know the X position is being stated explicitly there with the (1), but I'm not sure what to replace it with to get the position to move for each plot. This isn't a problem with other chart types, since they don't have the same field locating them.

Upvotes: 2

Views: 419

Answers (1)

theozh
theozh

Reputation: 25714

You can try the following. You can access the file in your file list by index via word(FILES,i). Check help word and help words. The code below assumes that you have some datafiles Data0*.dat in your directory. Maybe there is a smarter/shorter way to implement the xtic labels.

Code:

### boxplots from a list of files
reset session

# get a list of files (Windows)
FILES = system('dir /B "C:\Data\Data0*.dat"')

# set tics as filenames
set xtics ()    # remove xtics
set yrange [-2:27]
do for [i=1:words(FILES)] {
    set xtics add (word(FILES,i) i) rotate by 45 right
}

plot for [i=1:words(FILES)] word(FILES,i) u (i):2 w boxplot notitle
### end of code

Result:

enter image description here

Upvotes: 2

Related Questions