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.
Related
what i have:
csv data with timestamps in the first column, columns I want to plot selectively after that.
Every data point ist roughly ten minutes apart. Data is for 24 hours. Everything else set up nicely, examples below
What i want:
Be able to map the time data formatted on the x-axis (xrange?). Like xtics every n hours, in a given format (like "%T, %A"). Best configurable per column I want to plot (thinking about multiplot).
Data:
1545389400,39,0,0,1,664,2493,31.7
1545390000,37,0,0,1,736,3093,32.5
1545391200,33,0,0,1,664,4293,32.6
1545392400,28,0,0,1,704,5493,31.3
1545393000,26,0,0,0,649,6093,30.8
1545393600,24,0,0,0,632,6693,30.5
Code:
set title "Battery Log"
set datafile separator ','
set key center bottom outside
set border lw 0.5 lc '#959595'
set terminal svg dynamic rounded mouse lw 1 background '#272822'
set grid ytics
set ytics nomirror in
set yrange [0:100]
set xtics nomirror
set xtics rotate
set xdata time
set timefmt "%s"
set format x "%T, %A"
plot 'stats.csv' \
u 0:2 w l lc '#f92783' t columnheader, '' \
u 0:8 w l lc '#a6e22a' t columnheader
what about this?
### set time xtics
N = 3 # every n-th hour
set samples 100
set xdata time
set format x "%a, %H:%M"
set xtics rotate
set xtics N*3600
plot '+' u ($0*1200):(3*sin(x)+rand(0)) w lp pt 7 not
### end of code
which should give something like this, ticks every 3rd hour.
Set your N depending on the column you want to plot.
I plotted a figure with a classical x-axis, let's say from 0 to 25.
I'd like to have the x2-axis having the sqrt of x1-values and I didn't find anything about how to do it.
With my values here, x2range would be [0:5]
But tics shouldn't be linear, tha's why i didn't succeed to make it.
x2-tic 5 would match with 25, x2-tic 4 with 16, 3 with 9, etc.
Any Help ?
I hope there's a not-too-hard way to do this
Cheers.
That can be done since gnuplot 5 with the command set link, which links a secondary axis to the respective primary axis via a transformation function:
set xrange [0:25]
set link x2 via sqrt(x) inverse x**2
set x2tics
set xtics nomirror
plot x
The commands as given above will generate a warning because the mapping isn't unique. But you can ignore that warning as long as your xrange starts at value greater or equal to zero.
For gnuplot 4.6 you must place all x2tics manually:
set xrange [0:25]
set x2range [0:25]
set xtics nomirror
# delete all automatic tics but the one at 0
set x2tics (0)
# add all other tics
set for [i=1:5] x2tics add (sprintf('%d', i) i**2)
plot x
I am trying to plot a simple graph, x and y coordinates, however how my axis labels are not quite as I wish.
How can I change the '1e+08' and so on to their true value, 100000000
How can I shift the labels of the xtics down so they don't obscure the graph?
Can I print the coordinates in the graph of certian points, for example the dip between 2014-05-10-04-00 and 2014-05-10-08-00?
How can one add more intervals in the labels of the x axis?
Here is the input I'm using:
reset
clear
set output "BytesOverTime.png"
set title "Evolution of Bytes over Time"
set ylabel 'Bytes'
set xlabel 'Time'
set key off
set term png
set xdata time
set timefmt "%Y-%m-%d-%H-%M"
set format x "%Y-%m-%d-%H-%M"
set xtics rotate by 90 nomirror
set datafile separator ' '
set logscale y
plot "timeBytesAverage.out" using 1:2
And the file if its needed to test:
http://pastebin.com/raw.php?i=qqpeJj4V
How can I change the '1e+08' and so on to their true value, 100000000
set format y "%f"
or, as this will give you decimal numbers:
set format y "%.0f"
You may also have a look at
set format y "%.0s%cByte"
which will create MByte, GByte, ... (See right y-axis in my plot)
However, this will be to the base of 1000, not 1024.
How can I shift the labels of the xtics down so they don't obscure the graph?
set xtics rotate by 90 nomirror right
will right-align (left-flush) the tic marks
Can I print the coordinates in the graph of certian points, for example the dip between 2014-05-10-04-00 and 2014-05-10-08-00?
If you know the coordinates, yes:
set xtics add ("high" "2014-05-09-23-30", "low" "2014-05-10-22-30" )
The general syntax is:
set xtics add ( <label1> <position1>, <label2> <position2> , ...)
This will add the list of labels to the automatically generated labels. If you omit the word add, there will be no automatically generated labels, just those in your list.
How can one add more intervals in the labels of the x axis?
set xtics 3600
will generate a label every 3600 seconds, i.e. every hour. This does not work for log scale axes.
set mxtics 2
will cause the gap between two major (labeled) tics being divided into two smaller gaps, i.e. one minor tic mark between two major ones. (However, it seems not to be necessary here, as gnuplot decides to use 2 on it's own)
And here is the result:
Note that I also added
set y2tics
set y2range[1E8:1E12]
set format y2 "%.0s%cByte"
set logscale y2
to demonstrate this special format on the right y-axis.
And by the way: The format of the labels on the y-axis is independent from the format in the data file.
set timefmt "%Y-%m-%d-%H-%M" defines the format inside the file
set format x "%Y-%m-%d-%H-%M defines the format in the plot. So ou may do something like set format x "%Y-%m-%d %H:%M which is more readable.
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!
i have a csv file from 5 year malware data collected there are 2 columns the dates and the ips every date have 1 or more ips example
1/5/2013 12.234.123
1/5/2013 45.123.566
1/5/2013 100.546.12
1/6/2013 42.153.756
3/4/2014 75.356.258 etc... (every day for 5 years)
now i am trying to get the percentage difference between every month example:
November 2014 - 10%
December 2014 - 15%
i tried to put the percentage on y axis and in x2 axis but im getting some crazy results i am new to gnuplot and im still learning it here is the code i have right now:
set title 'Results Per Month'
set xlabel 'Date'
set ylabel 'Percentage'
set terminal png size 2800,900
set datafile sep ','
set xdata time
set timefmt '%Y/%m/%d'
set xrange['2009/3/22':'2014/12/02']
set xtics 30*24*60*60
set format x '%Y/%m'
set autoscale x2fix
set x2tics
set x2range[0:*]
set format x2 "%g %%"
set xtics nomirror rotate by -90
set grid ytics xtics
set ytics 10
set yrange [0:*]
set term png
set output 'file.png'
plot 'export.csv' using (timecolumn(1) - (tm_mday(timecolumn(1))-1)*24*60*60):(1) smooth frequency w lp pt 7 ps 2 notitle, \
'' using (($1-$2)/$1*100):x2ticlabels(2) axes x2y1 with points ps 2 lw 2
I would suggest you to use some external script for such kind of preprocessing (you can also do this on-the-fly). Yes, you can do this in gnuplot in two steps, but can become quite complicated and requires some more profound knowledge of gnuplot.
Here is a working script, but I won't go into detail about the many different aspects of the actual implementation:
set xdata time
set timefmt '%Y/%m/%d'
set datafile separator ','
set table 'temporaryfile.dat'
set format x '%Y/%m/%d'
plot 'export.csv' using (timecolumn(1) - (tm_mday(timecolumn(1))-1)*24*60*60):(1) smooth frequency
unset table
set y2tics
set ytics nomirror
set timefmt '"%Y/%m/%d"'
set format x '%b %Y'
set xtics rotate by 90 right
set datafile separator white
set yrange[0:*]
x0=x1=0
plot 'temporaryfile.dat' using 1:(strcol(3) eq "i" ? $2 : 1/0) w lp pt 7 ps 2 title 'IP count', \
'' using 1:(x1=x0, x0=$2, strcol(3) eq "i" ? ($0 == 0 || x0 == 0 ? 0 : (x0-x1)/x0 * 100.0) : 1/0) axes x1y2 w lp title 'percentual change'
Basically, first you plot the result data of smooth frequency into a second data file. Then you can plot this, and to the calculations for the percentages.
Please note, that I used a timeformat which corresponds to your test data (and the data of your previous question), which doesn't correspond with what you have in your script! Please pay attention to this.
Also note, that the timefmt before the actual plot must be extended by quote signs which are written around the dates in tmp.dat.
Finally, the strcol(3) eq 'i' is necessary to circumvent a gnuplot bug, which causes a last line to be written with invalid data.