1

I'm trying to create a graph which shows two lines from two different data sources – which are time-series. My problem is that one source has data for every day, and the other one has sporadic data (and starts later). Like the following image:

enter image description here

I use 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'd like just to plot the period where they both have data. Is that possible to do with GNUPlot?

Thanks :)

1 Answer 1

3

You can use the stats command to determine the xrange of both data files. This does not work in timedata mode, but since you have the time given as timestamp you can do this before setting 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 
Sign up to request clarification or add additional context in comments.

1 Comment

I had a gnuplot whitespace-field-seperated file with date/time in first field in quotes. I did not find a way to use this file with gnuplot stats command. Needed to set timefmt '"..."' to tell gnuplot first field had quotes around it. Rewriting the file as csv allowed me to use the stats command. '''set datafile sep whitespace''' put the datafile settings back so that I could plot using the whitespace-field-seperated file.

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.