gnuplot stock chart using date on x axis - gnuplot

I am trying to use gnuplot for the first time.
I am completely new to gnuplot. Please forgive any basic mistakes.
I am trying to plot a stock chart.
My data looks like the following:
Date Open High Low Close
21/04/2017 31.81 32.09 31.67 31.95
20/04/2017 31.55 32.02 31.45 31.91
19/04/2017 31.3 31.71 30.99 31.57
18/04/2017 31.78 31.84 31.06 31.3
17/04/2017 31.3 31.97 31.21 31.8
13/04/2017 31.26 31.48 31.16 31.19
12/04/2017 31.13 31.38 30.98 31.24
11/04/2017 31.37 31.66 30.86 31.2
I am using the following settings to plot the lines. I got them from another website.
set xdata time
set timefmt "%d/%m/%Y"
set xrange ["21/04/2015":"21/04/2017"]
set format x "%d/%m/%Y"
plot [0:100] 'chart.dat' using 0:2:3:4:5 notitle with financebars
However, the x-axis just has 01/01/1970. See attached pic.
Any assistance would be greatly appreciated. Thanks.

The plot command plot [0:100] ... using 0:2:3:4:5 takes column 0 for x, column 0 corresponds to the line number instead of the time column.
This command should work:
plot 'chart.dat' using 1:2:3:4:5 notitle with financebars

Related

Gnuplot: How to plot a 45 degree line?

I want to plot data from two different years and insert a 45 degree line so you can easily see if the value increased or decreased. X- and Y-axis will be from 0 to 1.
Thanks in advance for any help, much appreciated!
As Thor says, 45 degrees can be plotted simply by using plot x.
For a more general solution, you can use tan.
For example, to plot all lines from 0 degrees to 85 degrees
set angles degrees
set xrange [0:1]
set yrange [0:1]
plot x*tan(0), x*tan(5), x*tan(10), x*tan(15), x*tan(20), x*tan(25), x*tan(30), x*tan(35), x*tan(40), x*tan(45), x*tan(50), x*tan(55), x*tan(60), x*tan(65), x*tan(70), x*tan(75), x*tan(80), x*tan(85)

gnuplot multiple lines with Time on X axis

I've had a look through questions but still can't get this working.
My data set is like this:
[date] , [%cpu] , [mem]
23:00:39 , 21.9 , 2.1
23:00:44 , 21.8 , 2.1
23:00:49 , 21.8 , 2.1
23:00:54 , 21.8 , 2.1
23:00:59 , 21.7 , 2.1
My Gnuplot statements (just started using for this data) is:
set timefmt "%H:%m:%s"
set xdata time
set datafile sep ','
plot '/tmp/info' using 2 title 'cpu' with lines, '/tmp/info' using 3 title 'memory%' with lines
I get the following error:
Need full using spec for x time data
I've tried autoscale x , but I'm a bit lost, any help would be appreciated.
Time data requires that you always specify all columns to be used. (Note also the corrected timefmt):
set timefmt "%H:%M:%S"
set xdata time
set datafile sep ','
set style data lines
plot '/tmp/info' using 1:2 title 'cpu', '' using 1:3 title 'memory%'
The reason for this is, that the timefmt may also contain spaces, so that the data used for the time axis may come from two columns. Consider the following modified data file:
23:00:39 06/08/13 21.9 2.1
23:00:44 06/08/13 21.8 2.1
23:00:49 06/08/13 21.8 2.1
23:00:54 06/08/13 21.8 2.1
23:00:59 06/08/13 21.7 2.1
The plotting commands for this format are:
set timefmt "%H:%M:%S %d/%m/%Y"
set xdata time
set format x "%H:%M:%S"
set style data lines
plot 'mydata.dat' using 1:3 t 'cpu', '' using 1:4 t 'memory%'
To avoid confusion, it is always required that for time data all columns used by the plotting style (here with lines) are given explicitely with the using statement.
Your plot command look like this instead:
plot '/tmp/info' using 1:2 title 'cpu' with lines, '/tmp/info' using 1:3 title 'memory%' with lines
I had a similar issue with gnuplot where I had a data file like:
05:07:00 0.0769 0.0769 0.0000 0.0000 0.0000 0.0000 0.0000
05:08:00 0.2308 0.2308 0.0000 0.0000 0.0000 0.0000 0.0000
I was trying to use, but it was just not working
set xdata time
set timefmt "HH:MM:SS";
plot "wed" using 0:2 t 'wtf" w lines
The fix was a couple of things, primarily using the %'s in the timefmt string and only using one letter. Also using the set format x for the output was key (and using the first column as 1 - though I had tried that also earlier).
This is the minimal output script that is working for me:
set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M"
plot "wed" using 1:2 t 'my title' w lines

Two data points on same x coordinate overlapping

I started keeping a record of days that I've gone running, and the distance. I like plotting this using boxes to get an overview of how active I have been lately.
I ran into a problem today when I added yesterday's data.
As you can see from 05/04/13 there are two runs, and the plot shows two boxes on the same day (far left box). I like this behavior. 06/26/13 I had two runs again but this time the plot was only showing one (far right box). After a little playing around I realized it's because on 05/04, the larger number (in column 2) comes first, so the smaller number gets plotted on top of it. The opposite is true for 06/26, and the result is only being able to see the larger number for that day.
Is there a way to fix this without altering my data file?
If it's possible to do in the plot script, I wouldn't have to watch how I enter data to my file.
Here is the data:
05/04/13 1.59
05/04/13 0.81
05/05/13 1.56
05/06/13 1.90
05/08/13 2.77
05/11/13 2.19
05/12/13 0.93
05/14/13 2.50
05/15/13 1.04
05/16/13 1.66
06/02/13 4.02
06/03/13 1.80
06/04/13 1.04
06/05/13 0.93
06/12/13 1.18
06/15/13 1.78
06/16/13 1.26
06/19/13 0.86
06/21/13 0.93
06/26/13 1.05
06/26/13 1.39
The script:
set terminal x11 nopersist size 1200,645
unset mouse
unset key
unset label
unset grid
set boxwidth 86400 absolute
set style fill solid 1.00 border lt -1
set bmargin at screen 0.08
set xdata time
set timefmt x "%m/%d/%y"
set format x "%b %d"
set xtics 86400 nomirror rotate by -90
set mxtics 0
set xrange [ "05/01/13" : "06/30/13" ] noreverse nowriteback
set ylabel "Distance"
set ylabel textcolor lt -1 rotate by -270
set yrange [ 0.00000 : 4.50000 ] noreverse nowriteback
plot "/Users/user/Dropbox/nvalt/walks.txt" using 1:2 with boxes lt rgb "#777777"
An image of the plot:
For this type of files, it doesn't really matter in what order the days are, but as you mention, the ordering of the data is important. I was able to obtain the required output, by simply replacing
plot "/Users/user/Dropbox/nvalt/walks.txt" using 1:2 with boxes lt rgb "#777777"
By
plot "<sort -r /Users/user/Dropbox/nvalt/walks.txt" using 1:2 with boxes lt rgb "#777777"
This should also work for more than two data points for the same date.

Gnuplot, yerrorbar, text as x axis

I have the following data:
t4.8k 1.84 1.86 1.83
t5.8k 1.82 1.84 1.8
t7.10k 1.79 1.8 1.77
t8.8k 1.8 1.84 1.76
I need to plot this in GNU plot using yerror bars.
Column1 - dataset name. This is the xaxis scale.
Column2 - Y-Mean
Column3 - Y-Max
Column4 - Y-Min
Here is the plotting code that I use:
plot "chameleonConfidence.dat" using xtic(1):2:4:3 title "Ratio of Time Taken" with yerrorbars
But this gives me the following error
Warning: empty x range [4.94066e-324:4.94066e-324], adjusting to [4.94066e-324:4.94066e-324]
"chameleonConfidence.gplot", line 15: x_min should not equal x_max!
Can someone help me with this?
This works for me.
set xrange [-1:4]
TITLE="Ratio of Time Taken"
plot "chameleonConfidence.dat" using ($0):2:4:3:xticlabels(1) with yerrorbars title TITLE
the xtic function doesn't replace the x-values in your file -- it is an automagic extra field you can add to the using specification to add the xticlabels on your axis. Basically, you just need the line number ($0) to be the x value and then you are all set (moving xtic(1) to the end of your using spec)

Gnuplot: how to plot date / time chart

I would like to plot this kind of data:
X axis: dates
Y axis: time lenght
The data would looks like that:
22/02 51:10
25/02 63:10
01/03 50:55
23/03 52:10
I already done that for the X axis:
set xdata time
set timefmt "%d/%m"
But I don't know how to manage Y axis.
As Tom said, you can only use one timefmt. However, if it is possible to split your data to more columns like this:
22/02 51 10
25/02 63 10
01/03 50 55
23/03 52 10
you can then plot the time length by direct calculation, like this:
plot 'file' u 1:($2 + $3/60)
to plot minutes, or like this:
plot 'file' u 1:($2/60 + $3/3600)
to plot hours.
From ?xdata
There is currently only one timefmt,
which implies that all the time/date
columns must conform to this format.
So you need to alter your data somewhat to conform to one setting.
something like
00:00:22/02 51:10:22/02
00:00:25/02 63:10:22/02
00:00:01/03 50:55:22/02
00:00:23/03 52:10:22/02
Note that you can use command line tools to do this within gnuplot, see here
Once the file is edited you can read it like so
set xdata time
set ydata time
set timefmt "%M:%S:%d/%m"
set format x "%d/%m"
set format y "%M:%S"
plot "date_time.dat" u 1:2 w l

Resources