Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot line graphs with different x-range in one figure using gnuplot

Tags:

gnuplot

I have a dataset with 3 columns. For Example

ifile.txt
1     4    3
2     2    5
3     4    7
4     6    7
5     9    6
6     0    8
7     3    4
8     3    4
9     2    4
.     .    .
.     .    .

I would like to plot one line using 1:2 with x-range [3:7] and another line using 1:3 with x-range [5:9] in the same figure

I was trying to modify in plot command, but can't able to do.

plot\
 'ifile.txt' using 1:2 with xr [3:7],\
 'ifile.txt' using 1:3 with xr [5:9]
like image 620
Kay Avatar asked Dec 02 '25 15:12

Kay


1 Answers

Usually, if you need a common x-axis for both plots, you must filter the data in the using statement, and give all data points outside the desired range an invalid value, 1/0:

f(value, left, right) = (value < left || value > right ? 1/0 : value)

plot 'ifile.txt' using (f($1, 3, 7)):2,\
     '' using (f($1, 5, 9)):3
like image 144
Christoph Avatar answered Dec 05 '25 20:12

Christoph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!