2

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 Answer 1

3

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.sstatic.net/pNtZZ.png

Sign up to request clarification or add additional context in comments.

2 Comments

what if I dont know how much data I am handling? Like in this case I have DataA and DataB but I might generate another file that might look like this: DataA: 0 2 1 3 7 2 1 2 DataB: 3 2 6 4 1 1 DataC: 0 2 1 3 7 2 1 2 DataD: 3 2 6 4 1 1
Execute stats for your file without conditions, number of blocks is in a variable STATS_blocks. Then use a loop, look at do for [...] construction.

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.