Martina Coffaro
Martina Coffaro

Reputation: 1

reducing x axis gnuplot

I am struggling to find a way to reduce an x axis with gnuplot. I am plotting two different data set and , if you look at my plot (PLOT), I have a lot a space between the two data set I am plotting. I would like to "remove" them because if I do so, people will understand that the single data set is similar to a sinusoidal signal. Looking at this plot, one cannot say so.

I did not find anything useful in the web. Can you help me?

Thank you, Martina.

Upvotes: 0

Views: 362

Answers (3)

theozh
theozh

Reputation: 26200

Please always provide your code and data as text. It is important to know how your data is organized.

From the ranges of the plot you show (5.53e8 to 5.71e8), I assume that you have time data which is either from 1987/88 or from 2017/18 depending if you were using gnuplot 4.x or 5.x. The zero reference date has changed from Jan 1st 2000 in gnuplot 4.x to Jan 1st 1970 in gnuplot 5.x.

gnuplot 4.x
2017-07-18 02:10  to  2017-07-18 04:06
2018-01-30 23:10  to  2018-01-31 01:40

or

gnuplot 5.x
1987-07-19 02:10  to  1987-07-19 04:06
1988-01-31 23:10  to  1988-02-01 01:40

Anyway, your two datasets have both a range of about only 2 hours, but they are separated by about half a year. As you already noticed this will not give a reasonable plot if you simply plot them as timedata. Therefore, you simply need to shift the second dataset such that it will be "connected" with the first one. As a consequence, absolute time/date do not make sense anymore, but relative hours "%tH" from the beginning of the first dataset will be suitable (check help time_specifiers examples).

Hence, you have to find out the first and last date/time values of your datasets. One possibility would be to use stats (check help stats) and timecolumn() (check help timecolumn). You will find these values in t1_min, t1_max, t2_min and t2_max.

For comparison, the code below plots your graph as you did and as you would expect.

Code:

### plot timedata with offset (gnuplot 5.x)
reset session

myTimeFmt = "%Y-%m-%d %H:%M"

# create some random test data
set print $Data1
    t0 = strptime(myTimeFmt,"2017-07-18 02:10")
    t1 = strptime(myTimeFmt,"2017-07-18 04:06")
    do for [t=t0:t1:5*60] {    # every 5 minutes
        print sprintf("%s %g",strftime(myTimeFmt,t), rand(0))
    }
set print $Data2
    t0 = strptime(myTimeFmt,"2018-01-30 23:10")
    t1 = strptime(myTimeFmt,"2018-01-31 01:40")
    do for [t=t0:t1:5*60] {    # every 5 minutes
        print sprintf("%s %g",strftime(myTimeFmt,t), rand(0))
    }
set print

set key out right
set multiplot layout 2,1
    set format x "%b %d\n%Y" timedate
    plot $Data1 u (timecolumn(1,myTimeFmt)):3 w lp pt 6 lc "red"  ti "Data1", \
         $Data2 u (timecolumn(1,myTimeFmt)):3 w lp pt 6 lc "blue" ti "Data2"

    stats $Data1 u (timecolumn(1,myTimeFmt)) name "t1" nooutput
    stats $Data2 u (timecolumn(1,myTimeFmt)) name "t2" nooutput
    set format x "%tH:%tM" timedate
    plot $Data1 u (timecolumn(1,myTimeFmt)-t1_min):3                 w lp pt 6 lc "red"  ti "Data1", \
         $Data2 u (timecolumn(1,myTimeFmt)-t2_min+(t1_max-t1_min)):3 w lp pt 6 lc "blue" ti "Data2"

unset multiplot
### end of code

Result:

enter image description here

Upvotes: 0

Martina Coffaro
Martina Coffaro

Reputation: 1

Thank you for your tips. It will be useful in the future. However this does not solve my problem. In fact in this way I will have the two dataset overlapped, as in this plot. Instead I would like to have the two data set as a continuum, avoiding all the space you can see in the plot of my first post.

Thank you again.

Upvotes: 0

user8153
user8153

Reputation: 4095

You can have two plots use different x axes, but the same y axis, by specifying axes x2y1 for one of them. For example, something like

set xtics nomirror
set x2tics
plot "file1" w p, "file2" axes x2y1 w p

should do what you want. For other possible combinations see help axes.

Upvotes: 0

Related Questions