Gaurav Singh
Gaurav Singh

Reputation: 307

gnuplot value on Y-axis

I have a file which contains two column data. when plotted, it looks like gnuplot image

Green line is showing mean. I want to show mean value on Y-axis. Is it possible? code:

set style data lines
set termoption enhanced
set term png
set title "17th oct"
stats 'data/17-10-2013' using 1:2 nooutput
set xdata time
set timefmt "%s"
set format x "%H"
set output "images/17_DB.png"
plot "data/17-10-2013" using 1:3 title " Data" , STATS_mean_y title " Mean"

Upvotes: 1

Views: 1675

Answers (1)

Christoph
Christoph

Reputation: 48440

Here are three different options to display the value:

set term pngcairo enhanced
set output "images/17_DB.png"

set title "17th oct"
stats 'data/17-10-2013' using 1:2 nooutput
set xdata time
set timefmt "%s"
set format x "%H"

# first option    
set ytics add (sprintf('%.1f', STATS_mean_y) STATS_mean_y)

# second option
set ytics add ('' STATS_mean_y)
set rmargin 3
set label left at graph 1.05,first STATS_mean_y sprintf('%.1f', STATS_mean_y)

set style data lines

# third option inside the key label
plot "data/17-10-2013" using 1:3 title "Data" , \
     STATS_mean_y title sprintf("Mean = %.1f", STATS_mean_y)

Here some notes about the different options:

  1. The first option is the easiest, but the label could overlap with another label (here with the 0).
  2. The second option adds an empty mayor tic, and places the label on the right side. This requires the right margin to be increased manually (you may need to use another value, e.g. set rmargin 2 and other coordinates).
  3. The third option just places the value in the key (legend) entry.

For a nicer x-axis, you may want to add set autoscale xfix, which gets you rid of the empty space on the right side.

Upvotes: 2

Related Questions