GNUplot mixes data producing output - gnuplot

I am trying to plot the graph using gnuplot, but I am getting strange result. gnuplot for some reason makes larger gaps at two dates and places January 29th over January 31. The commands I use:
set terminal pngcairo size 1600,800 enhanced font "Helvetica,16"
set output 'Pic.png'
set timefmt '%Y-%m-%d %H:%M:%S'
set xdata time
set format x '%Y-%m-%d %H:%M:%S'
set title "Title"
set xlabel "Date"
set ylabel "Level"
set xtics timedate
set xtics rotate
nth(countCol,labelCol,n) = ((int(column(countCol)) % n == 0) ? stringcolumn(labelCol) : "")
plot 'data.txt' using 1:6:xtic(1) with l title 'V' lw 3, \
'data.txt' using 1:2 with l title 'D' lw 3, \
'data.txt' using 1:3 with l title 'H' lw 3
Output:
Note - nth is just for fun - I tried to get the xtick at every nth date, but failed.
Behaviour is the same with gnuplot 5.0.3/64 and 5.2.2/64 on linux (I can provide the data file - do not see it fit to post 60 lines of data I use)
Data:
2018-01-27 16427682 16427855 -173 11.9176 1378438.77 2376.61
2018-01-28 16609257 16609139 118 11.9371 1391397.99 2398.96
2018-01-29 5185798 5342036 -156238 11.5996 447066.96 770.80
2018-01-30 0 0 0 11.432 0 0
2018-01-31 0 0 0 11.4451 0 0
2018-02-01 0 0 0 11.4493 0 0
2018-02-02 0 0 0 11.4545 0 0
2018-02-03 0 0 0 11.4491 0 0
2018-02-04 0 0 0 11.4169 0 0
2018-02-05 0 0 0 11.4167 0 0
2018-02-06 0 0 0 11.4124 0 0
2018-02-07 0 0 0 11.4013 0 0
2018-02-08 0 0 0 11.3926 0 0
2018-02-09 0 0 0 11.3861 0 0
2018-02-10 16958731 16273921 684810 11.8858 1426806.02 2460.01
2018-02-11 16498622 16498627 -5 11.854 1391818.96 2399.68

Related

How to plot energy diagram using gnuplot

I have data file:
0 0 3 -0.17 6 -0.05
0 0 3 -0.23 6 0.90
0 0 3 -0.41 6 0.50
0 0 3 -0.50 6 -0.33
0 0 3 -0.20 6 0.80
I want to plot the figure like this which connects each point in the lines. Can you tell me how?
The following suggestion uses the plotting styles with boxxyerror, with vectors and with labels.
The zero level gets the color of the last entry because everything is plotted on top of each other. Check the following example as starting point for further tweaking.
Script:
### energy diagram
reset session
$Data <<EOD
0 0 3 -0.17 6 -0.05 A_{one}
0 0 3 -0.23 6 0.90 B_{two}
0 0 3 -0.41 6 0.50 C_{three}
0 0 3 -0.50 6 -0.33 D_{four}
0 0 3 -0.20 6 0.80 E_{five}
EOD
set key noautotitle
set xrange [-1:8]
myWidth = 0.3
plot for [i=1:3] $Data u (column(2*i-1)):(column(i*2)):(myWidth):(0):0:xtic(i*2-1) w boxxy lw 3 lc var, \
for [i=1:2] '' u (column(2*i-1)+myWidth):(column(i*2)): \
(column(2*i+1)-column(2*i-1)-2*myWidth):(column(i*2+2)-column(i*2)):0 w vec nohead lw 1 dt 3 lc var, \
'' u 5:6:7:0 w labels offset 6,0 tc var font ",16"
### end of script
Result:
Addition:
From your comments: If the levels are to close such that the labels overlap, you could add an individual offset (here in column 8).
Check the following example where the data is modified that the levels B and E are very close.
Script:
Edit after OP's comment: simplifications, with xerrorbar instead of with boxxyerror and with custom xtics
Edit 2: simplified input data
reduce the input data to the minimum
add xticlabel from columnheader
use column number as x-coordinate. Mind the difference in ...$Data u (col):col:...: e.g. if col=1, (col) is the fixed value of 1, and col is the value from column 1.
### energy diagram with individual offset of labels
reset session
$Data <<EOD
A B C Label Offset
0.0 -0.17 -0.05 A_{one} 0
0.0 -0.23 0.90 B_{two} 0.05
0.0 -0.41 0.50 C_{three} 0
0.0 -0.50 -0.33 D_{four} 0
0.0 -0.20 0.85 E_{five} -0.05
EOD
set key noautotitle
set errorbars 0
set offset 0.5,0.5,0,0
myWidth = 0.1
plot for [col=1:3] $Data u (col):col:(myWidth):0:xtic(columnhead(col)) w xerr lw 3 ps 0 lc var, \
for [col=1:2] '' u (col+myWidth):col:(1-2*myWidth):(column(col+1)-column(col)):0 \
w vec nohead lw 1 dt 3 lc var, \
'' u (3+myWidth):($3+$5):4:0 w labels left offset 1,0 tc var font ",16"
### end of script
Result:

gnuplot, splot, xyz equal scale, graph too small

I would like to plot a 3D picture from data (below). All axis should have equal scale. However resulting picture is too small relative to canvas size.
How can I fill most canvas with the plot?
I tried changing canvas size, or setting size 1,1.
Data (5 squares):
0 0 0
1 0 0
1 0 1
0 0 1
0 0 0
0 0 0
1 0 0
1 1 0
0 1 0
0 0 0
0 0 0
0 1 0
0 1 1
0 0 1
0 0 0
0 0 0
-1 0 0
-1 0 1
0 0 1
0 0 0
0 0 0
-1 0 0
-1 1 0
0 1 0
0 0 0
I am using gnuplot 4.4 patchlevel 3,
commands:
set term pdfcairo size 2,1;
set xrange [-1.05:1.05];
set yrange [-0.05:1.05];
set zrange [-0.05:1.05];
unset key; unset border; unset tics;
set lmargin 0; set rmargin 0; set tmargin 0; set bmargin 0;
set view equal xyz;
set output 'address';
splot 'data.txt' w l;
unset output;
Thank you.
The "set view" command contains two scale factors. The first scale factor scaless the entire plot, the second one scale the z axis only.
Syntax:
set view <rot_x>{,{<rot_z>}{,{<scale>}{,<scale_z>}}}
The easiest way to adjust this is using an interactive terminal. Click and drag with the middle mouse button to adjust the scale factors to taste. Then use show view to note the current values. Add those to your script. For example to scale the whole thing by a factor of two:
set view ,,2.0

How to set different heights for separate plots using multiplot

How can one set different heights for two or more plots in multiplot-mode using set size <x>,<y> respecting correct arrangement for the x-axes of the plots? Following problem: I've got a heatmap plot and another linespoint plot with the same time axis. The heatmap plot contains way more information and should use e.g. 80% of the canvas height. Using
set multiplot layout 2,1 margins .1,.8,.05,.95 spacing .05
sets the plots in perfect arrangement but without the possibility to change heights; or at least I didn't manage to get it right. Here are two examples using code from the gnuplot demopage:
$map2 << EOD
0 0 5
0 1 4
0 2 3
0 3 1
0 4 0
1 0 2
1 1 2
1 2 0
1 3 0
1 4 1
2 0 0
2 1 0
2 2 0
2 3 1
2 4 0
3 0 0
3 1 0
3 2 0
3 3 2
3 4 3
4 0 0
4 1 1
4 2 2
4 3 4
4 4 3
EOD
set multiplot layout 2,1 margins .1,.8,.05,.95 spacing .05
plot '$map2' using 2:1:3 with image
plot sin(x)*cos(x)**2, tan(x)
unset multiplot
which results:
Setting explicit sizes and origins before the plotting commands doesn't have any effect.
Plotting without the margins/spacing option and instead setting explicit sizes and origins for each plot one could only guess the correct x-width for the second plot. Guessing it between .85 and .9 in the code:
$map2 << EOD
0 0 5
0 1 4
0 2 3
0 3 1
0 4 0
1 0 2
1 1 2
1 2 0
1 3 0
1 4 1
2 0 0
2 1 0
2 2 0
2 3 1
2 4 0
3 0 0
3 1 0
3 2 0
3 3 2
3 4 3
4 0 0
4 1 1
4 2 2
4 3 4
4 4 3
EOD
set multiplot layout 2,1
set size 1,.75
set origin 0.025,.25
plot '$map2' using 2:1:3 with image
set size .85,.25 # <---
set origin 0.025,0
plot sin(x)*cos(x)**2, tan(x)
unset multiplot
lets me plot it like that:
I hope I could explain my question and thanks a lot for your help! It is highly appreciated!
If I have understood your question, you have to only change rmargin and lmargin:
set size 1,1
set origin 0,0
unset bmargin, unset lmargin, unset tmargin, unset rmargin
set multiplot
set size 1,0.8
set origin 0,0.2
set lmargin at screen 0.1
set tmargin at screen 0.95
set rmargin at screen 0.9
plot 'map2.dat' using 2:1:3 with image
set size 1,0.2
set origin 0,0
set tmargin 0
set lmargin at screen 0.1
set bmargin at screen 0.1
set rmargin at screen 0.9
plot[GPVAL_X_MIN:GPVAL_X_MAX] sin(x)*cos(x)**2, tan(x)
unset multiplot

gif animation creation with gnuplot, using a single file with keeping previous data on the plot

This question was answered partly in couple of places, like Create a gif in Gnuplot from a single file.
Yet there is a problem, the provided answer is going to plot only points at each index.
lets say I have the following data set:
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
my code for creating the gif is :
set terminal gif animate delay 50
set output 'foobar.gif'
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5
stats 'Datafile' nooutput
do for [i=1:int(STATS_blocks)] {
splot 'Datafile' index (i-1) matrix with p ls 1
}
This code will generate a gif that just contains the data of each index. while I want the second dataset to be added to the first one the animation.
How should I do that?
Well I managed to find the answer by my own, and sorry #Christoph the easiest answer is always erasing the question. Yes it is possible with adding a second loop. I knew that I needed to add a second loop, but I was not sure how to:
set terminal gif animate delay 50
set output 'foobar.gif'
set grid
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5
stats 'Datafile' nooutput
set ztics 1
set zrange [-2:7]
do for [i=1:int(STATS_blocks)] {
splot for [j=1:i] 'Datafile' index (j-1) matrix notitle with p ls 1
}
This will generate what I want.

gnuplot hypertext is not working

I have the below gnuplot script, I'm trying to display the third column when the mouse hover over a point of the plot.
set title "Cloud"
set xlabel "Date"
set ylabel "Number"
filename ='data.dat'
stats filename using 4 nooutput
set xdata time
set timefmt '%Y-%m-%d'
set format x '%Y'
rand_x(x) = x + 60*60*24*7 * (rand(0) - 0.5)
rand_y(y) = y + (rand(0) - 0.5)
set xrange [ "1995-01-19":"2013-12-12" ]
plot for [i=0:int(STATS_max)-1] filename \
using (rand_x(timecolumn(1))):(i < $4 ? rand_y($2) : 1/0):3 pointtype 7 linecolor palette notitle
u 0:1:2 with labels hypertext point pt 7 ps var lc rgb "#ffee99"
And the data file looks like below:
1999-01-19 21 0 1
2009-07-01 0 1 1
2008-08-20 2 1 1
2008-12-18 1 1 1
2004-05-12 4 1 1
2009-07-29 2 1 1
2008-08-07 0 1 1
2006-03-08 1 1 1
2004-08-31 9 1 1
2001-03-27 12 1 1
2009-08-19 0 1 1
2010-07-14 2 1 1
2009-06-24 0 1 1
2009-11-11 0 1 1
2010-10-13 0 1 1
2012-02-22 0 1 1
2011-05-11 0 1 1
2011-03-03 0 1 1
2011-09-21 0 1 1
2011-12-20 0 1 1
2011-10-05 0 1 1
2012-05-03 0 1 1
2011-10-05 0 2 1
2013-01-09 0 2 1
2011-06-03 0 2 1
So can you please tell me what's wrong with my script?
Thanks.
First a remark for the readers: hypertext works only with the 4.7 development version.
To your problem: For plotting the labels, you must also use the same x and y columns 1 and 2 (you use 0 and 1). And you need the third column for the labels and a fourth one for the ps var. So your plot part for the labels is:
plot for [i=0:int(STATS_max)-1] filename \
using (rand_x(timecolumn(1))):(i < $4 ? rand_y($2) : 1/0):3 pointtype 7 linecolor palette notitle,\
'' u 1:2:3:3 with labels hypertext point pt 7 ps var lc rgb "#ffee99"

Resources