简体   繁体   中英

gnuplot: mark/highlight area (part of linegraph)

my data is quite simple, just a timestamp and a number like this:

  • 2013-01-23 08:27:55 2801
  • 2013-01-23 08:33:13 2801
  • 2013-01-23 08:38:31 2660
  • 2013-01-23 08:43:49 2785
  • 2013-01-23 08:49:07 2785

I get the data from a another system. Space between date and time, and tabulator between "date time" and the number.

The whole time window is a few hours .. a couple of days. This overall time window contains one or more interesting parts (typically few..several hours), and I would like to mark or highlight these interesting parts somehow to make it easier and faster to analyse the graphs.

Th einteresting time window would need to be specified manually, eg from 2014-01-23 10:00:00 to 2013-01-24 12:00:00 for 2 hour window.

Drawing a rectancle to the background of the linegraph is one possibility, and changing the line color (or something similar) is another.

How can I do that from manually/separately defined time stamps? The best I was able to find was splitting the data with empty lines, and use something like this (from http://www.gnuplotting.org/introduction/plotting-data/ ):

set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5   # --- blue
set style line 2 lc rgb '#dd181f' lt 1 lw 2 pt 5 ps 1.5   # --- red
plot 'plotting-data3.dat' index 0 with linespoints ls 1, '' index 1 with linespoints ls 2

But splitting the data is a bit arduous (?); I'm looking for elegant gnuplot means to achive the goal. Robust splitting could be possible as well, if thats really the best alternative.

Below is the plotting function, works well but I'd like to mark/highlight selected parts of the graph.

-Paavo

function my_gnuplot {
  if [ $# -ne 3 -o -z "$1" -o -z "$2" -o -z "$3" ]
  then
    echo $0 $FUNCNAME Invalid parameters, exiting
    exit 3
  fi

  sid="$1" ; shift
  stime="$1" ; shift
  etime="$1" ; shift

  if [ $sid -gt 0 -a $sid -lt 10 ]
  then
    title=0$sid
  else
    title=$sid
  fi

  gnuplot <<- EOF
  reset
  set terminal png size 1800,900 enhanced font myfont.ttf 10

  set xdata time
  set timefmt "%Y-%m-%d %H:%M:%S"
  set format x "%Y-%m-%d %H:%M"

  set title "SID=$title from $stime to $etime"
  set grid

  set xrange [ "$stime" : "$etime" ]
  set yrange [ -2000 : 6000 ]
  set style data linespoints

  plot "sid_data_$sid.txt" using 1:9 notitle
        EOF
}

You can use rectangles to fill the space pretty easily:

set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set object 1 rectangle from "2013-01-23 08:33:13",graph 0 to "2013-01-23 08:43:49",graph 1 fs solid fc rgb "red" behind
plot 'test.dat' u 1:3 w lines ls -1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM