1
votes

I have a data file file.dat arranged in this format:

 DataA:
 0 2
 1 3
 7 2
 1 2


 DataB:
 3 2
 6 4
 1 1

I want to get 2 plots from this data file.

  1. a simple plot of these points.
  2. A plot of number of points in each data sets. e.g (DataA has 4 points and DataB has 3 points)

For generating the first plot I am using this

set key autotitle columnheader right 
plot for [i=0:1] 'file.dat' using 1:2 index i with lp

For the other plot I just want a simple bar chart like this:

plot 2

Where y-axis tells the number of points DataA and DataB have.

I don't understand how to count the points present in the list, simultaneously plotting the data set too.

P.S Can I also get both of the plots side by side?

EDIT: The file.dat can contain multiple datas. e.g

 DataA:
 0 2
 1 3
 7 2
 1 2

 .
 .
 .


DataZ:
3 2
6 4
1

1 Answers

2
votes

To count points, use stats. To plot side by side, use multiplot.

stats 'file.dat' using 1:2 every :::0::0  name 'A' # to get stats with prefix 'A_'
stats 'file.dat' using 1:2 every :::1::1  name 'B'
set multiplot layout 1,2 # 1 row, 2 columns
plot for [i=0:1] 'file.dat' using 1:2 index i with lp
set object 1 rect from 1,0 to 3,A_records fc rgb 'red'
set object 2 rect from 5,0 to 7,B_records fc rgb 'red'
set xrange [0:8]
max=(A_records>B_records ? A_records:B_records)+0.5
set yrange [0:max]
set format x ''
unset xtics
set xtics ('DataA' 2, 'DataB' 6)
plot -10 notitle
unset multiplot

https://i.stack.imgur.com/pNtZZ.png