gnuplot value on Y-axis - gnuplot

I have a file which contains two column data. when plotted, it looks like
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"

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:
The first option is the easiest, but the label could overlap with another label (here with the 0).
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).
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.

Related

set xtics by <start>, <incr> in gnuplot does not work

I plot with gnuplot the following:
$Data <<EOD
time_,value
1-23:59:58,1
1-23:59:59,2
2-00:00:00,3
2-00:00:01,4
2-00:00:02,5
EOD
set term png size 800,600
set output "ask.png"
set datafile separator comma
set grid
set xdata time
set timefmt "%d-%H:%M:%S"
set format x "%H:%M:%S"
set xtics nomirror
set autoscale xfix
set autoscale x2fix
startnumber=1
xticdata=2
mxticdata=2
set xtics xticdata rotate
set mxtics mxticdata
set x2data
set x2tics startnumber, xticdata rotate
set mx2tics mxticdata
set link x2 via x+1 inverse x-1
plot $Data using 1:2 title columnheader(2)
set output
Data of the column 2 which contains nearly 50,000 records is value of a parameter. set link has to be used to align x-axis and x2-axis. And I want to show x2tic labels for counter/index which must be related to the time(column 1).
The output is alright, but you can see from the attached figure that the labels on x2-axis are big numbers, which is not what I want. I want to get labels like "1,3,5...".
So what's wrong with my code? And how to correct it? Thanks.
If the idea is that the x2 axis should be labeled with the content of column 2 regardless of its numerical relationship to column 1, then you can use:
set xdata time
set timefmt "%d-%H:%M:%S"
set format x "%H:%M:%S"
set xtics nomirror
set x2tics nomirror
set link x2
plot $Data using 1:2:x2ticlabels( int($0+1)%2 ? strcol(2) : "" ) title columnheader(2)
This creates one x2 axis tick label for every data point. The even-numbered ones to blank and the odd-numbered ones are set to whatever is in column 2.
the quickest fix would be
set link x2 via x-86397 inverse x+86397
But it depends what timesteps you have and what numbers you have in column 2. If your time step it is strictly regular and 1 second, and column 2 just counts up, then column 2 is redundant.
Timedata is handled internally as seconds from 01.01.1970 00:00:00.
One day has 86400 seconds. Check help time/date.

Time conversion does not work in gnuplot

I have the following snippet to have a graph output via gnuplot.
set datafile separator ","
set title "Memory"
set xlabel "Values"
set ylabel "Date"
set ydata time
set timefmt "%H"
set format y "%d/%m/%Y"
set key left top
set grid
plot 'memory-memory-buffered_combined' using 0:2 titl "1" with lines,\
'memory-memory-cached_combined' using 0:2 title "2" with lines
cat
pause -1
However, when I have the result it starts from 1970.
The first 5 lines of the csv I am reading;
epoch,value
1478193413.596,72910
1478193473.412,134432
1478193413.158,65449
1478193411.929,60157
So, it is actually November 2016.
Which part of my script should be different?
set datafile separator ","
set title "irq"
set xlabel "Date"
set ylabel "Values"
set xdata time
set timefmt "%s"
set format x "%d/%m/%Y"
set key right top
set grid
set terminal jpeg size 3600,2100 enhanced font helvetica 20
set output "irq.jpg"
plot "/irq/irq-16_combined" using 1:2 title "irq-16" with lines
I applied some changes on the script, however it is still inconsistent. Out of 100 scripts which have same pattern and similar files with same column names and values, only one still have output where time starts from 1970. Have any of you experienced such issue?

Weather data displayed with gnuplot

i'm currently trying to plot weather data with gnuplot using a text document containing a utc timestamp in the first column, and the temperature in the second and third.
set term png size 1920,660
set output "Today.png"
set datafile missing '0'
set ylabel "Temperature"
set grid ytics
set timefmt "%s"
set format x "%H:%M:%S"
set xdata time
set xtics rotate
plot "Data.dat" using 1:2 with lines lt rgb "red" t "Inside", "Data2.dat" using 1:3 with lines lt rgb "blue" t "Outside"
This is working and displaying the graphs except for one thing:
The data is automatically updated every couple hours. So when creating the image at 10 am it will display data from 0-10 am. Instead I want it to always display one complete day at a time, so over the course of the day, you can see the graph "grow" from left to right.
I tried inserting the following code:
set xrange ["00:00:00":"23:59:59"]
but it does not display anything then.
Any suggestions on how to accomplish that?

configure gnuplot to handle timeseries like excel

I am trying to graph events over time with gnuplot. Excel's default behavior produces a more readable graph.
I would like my graph from gnuplot to look like Excel's.
set terminal png size 1200,800
set xdata time
set timefmt "%Y-%m-%d_%H-%M"
set output "graph.png"
set xrange ["2015-02-01_08-54":"2015-02-01_23-20"]
set yrange [0:70]
set grid
set xlabel "24-Hour"
set ylabel "Events"
set title "Events"
plot "events.dat" using 1:2 index 0 title "events" with filledcurves ls 1
I've spent many hours manipulating source data and plot.conf, but it's not clear to me what Excel is doing differently.
Gnuplot Output:
Excel Output:
Excel plots with a wrong x-scale: it ignores the time values, and puts the values given in the first column at equidistant x-values as labels.
To get the same behavior with gnuplot, you must use xticlabel to place the values in the first column as tic labels, and use the row number (column 0) as x-values:
set xtics rotate by 90 right noenhanced
plot "events.dat" using 0:2:xticlabel(1) title "events" with filledcurves
Now, this would give you rather unreadable labels, because that are too many. With some tweaks you get a nicer result:
set terminal pngcairo size 1200,800
set output "graph.png"
set yrange [0:70]
set grid y
set xlabel "24-Hour"
set ylabel "Events"
set xtics out nomirror scale 0.5 rotate by 90 right font ',8' noenhanced
plot "events.dat" using 0:2:xticlabel(int($0) % 5 == 0 ? strcol(1) : '') title "events" with filledcurves
Disclaimer: Please use this script only to understand what Excel does and not to reproduce it, because it gives a very wrong impression of the actual time spans in which your events happen!

gnuplot display y2 values on x2

I have the following graph:
first data set display searches.
second data set display clicks.
y1 shows searches scale, y2 shows click scale.
on the x1 I have time values displayed.
I wish to display clicks values (each hour) on x2 (the upper axis).
When I add the command set x2tics it displays the searches data and not the clicks like I wished.
How do I change it so it will display the clicks unit?
Gnuplot script:
set xlabel "Time"
set ylabel "Times"
set y2range [0:55000]
set y2tics 0, 1000
set ytics nomirror
set datafile separator "|"
set title "History of searches"
set xdata time # The x axis data is time
set timefmt "%Y-%m-%d %H:%M" # The dates in the file look like 10-Jun-04
set format x "%d/%m\n%H:%M"
set grid
set terminal png size 1024,768 # gnuplot recommends setting terminal before output
set output "outputFILE.png" # The output filename; to be set after setting
# terminal
load "labelsFILE"
plot 'goodFILE' using 1:3 lt 2 with lines t 'Success' , 'clicksFILE' using 1:2 lt 5 with lines t 'Clicks right Y' axis x1y2
replot
Graph:
graph http://img42.imageshack.us/img42/1269/wu0b.png
Ok, so to get started, here is how you can set a label with the number of clicks as follows (using you data file names):
plot 'goodFILE' using 1:3 lt 2 with lines t 'Success',\
'clicksFILE' using 1:2 lt 5 with lines t 'Clicks right Y' axis x1y2,\
'' using 1:2:(sprintf("%dk", int($2/1000.0))) with labels axis x1y2 offset 0,1 t ''
Just add this as plotting command, and it should work just fine.
To illustrate, how the labels might look like, here is an example with some dummy data:
set terminal pngcairo
set output 'blubb.png'
set xlabel "Time"
set ylabel "Times"
set y2label "Clicks per hour"
set y2range [0:10000]
set yrange [0:1]
set ytics nomirror
set y2tics
set key left
set samples 11
set xrange[0:10000]
plot '+' using 1:1:(sprintf("%dk", int($1/1000.0))) every ::1::9 with labels axis x1y2 offset 0,1 t '',\
'' using 1:1 with linespoints axis x1y2 pt 7 t 'Clicks per hour'
Which gives you:

Resources