Plotting only general data in a dataset with GNUPlot

I am trying to create a graph that shows two rows from two different data sources that are time series. My problem is that one source has data for each day and the other has sporadic data (and starts later). As shown below:

enter image description here

I am using the following code:

set autoscale xfixmax
set autoscale xfixmin
set xdata time
set timefmt "%s"
set format x "%m/%y"
set y2tics

set terminal png size 1000,500

set datafile sep ','

plot 'a.csv' using 1:2 with line lw 1.2 title 'a' axes x1y1, \
 'b.csv'  using 2:5 with steps lw 2 title 'b' axes x1y2 

      

I would just like to talk about the period when they both have data. Is this possible with GNUPlot?

Thank:)

+1


source to share


1 answer


You can use the command stats

to determine the xrange of both data files. This doesn't work in timedata mode, but since you have the time specified as a timestamp, you can do this before setting it to timedata mode:



set datafile sep ','

stats 'a.csv' using 1:2 prefix 'a'
stats 'b.csv' using 2:5 prefix 'b'

xmin = (a_min_x < b_min_x ? b_min_x : a_min_x)
xmax = (a_max_x < b_max_x ? a_max_x : b_max_x)

set xdata time
set timefmt "%s"
set format x "%m/%y"
set y2tics
set xrange[xmin:xmax]

set terminal png size 1000,500

plot 'a.csv' using 1:2 with line lw 1.2 title 'a' axes x1y1, \
'b.csv'  using 2:5 with steps lw 2 title 'b' axes x1y2 

      

+2


source







All Articles