Given this file of data:
#date foo bar
2018-10-12_11-54-52 12 1
2018-10-12_11-55-09 14 7
2018-10-12_11-55-16 13 10
2018-10-12_13-00-01 15 8
2018-10-12_14-00-01 12 9
and this set of plot commands:
set timefmt "%Y-%m-%d_%H-%M-%S"
set xrange ["2018-10-12_11-54-52" : "2018-10-12_14-00-01"]
plot 'datafile.txt' using 1:2 with linespoints linestyle 1
plot 'datafile.txt' using 1:3 with linespoints linestyle 1
when I run gnuplot with gnuplot -p cmd_file.txt it errors with
line 3: Can't plot with an empty x range!
The xrange should be over 125 minutes long. Why does gnuplot think it is empty?
Related
I am using Gnuplot to show the precipitation measured during the last 13 monthts. Data is read from two data files, rain.dat and snow.dat. I use impulses, but on days with both rain and snow the impulses are plotted over each other. It had been better if the impulses were stacked.
#!/usr/bin/gnuplot -persist
set xdata time
set timefmt "%d.%m.%Y"
set ylabel "Precipitation (mm)"
set xrange ["01.`date --date="1 year ago" +%m.%Y`":"01`date --date="1 month" +.%m.%Y`"]
set xtics "01.`date --date="1 year ago" +%m.%Y`",2800000, \
"01.`date --date="now 1 month" +%m.%Y`" offset 3,0.2
set format x "%b"
set style line 100 lt 3 lc rgb "gray" lw 0.5
set style line 101 lt 3 lc rgb "gray" lw 0.5
set grid back xtics ytics mytics ls 100, ls 100, ls 101
set terminal png size 1000,200
set output 'precipitation.png'
plot 'rain.dat' using 1:2 title 'Rain' w impulses lt rgb '#ff0000' lw 4 , \
'snow.dat' using 1:2 title 'Snow' w impulses lt rgb '#0000ff' lw 2
rain.dat:
16.02.2021 8
22.02.2021 6
04.03.2021 10
08.03.2021 13
14.03.2021 5
snow.dat:
19.02.2021 19
22.02.2021 10
04.03.2021 14
12.03.2021 8
How can impulses be stacked with Gnuplot?
As #Ethan already mentioned, with impulses will always start at 0. If you don't mind some little extra effort, you can mimic "stacking" impulses if you first plot the sum of rain and snow with the "snow color", and then plot rain alone with the "rain color" on top of it.
But how do you get the sum of rain and snow?
plot your datablocks (or files) into the temporary datablock $Temp.
plot datablock $Temp into the datablock $SnowAndRain using the option smooth frequency which sums up snow and rain for each day. Check help smooth.
Script: (works for gnuplot>=5.2.0, Sept. 2017)
### "stacked" impulses
reset session
$Rain <<EOD
16.02.2021 8
22.02.2021 6
04.03.2021 10
08.03.2021 13
14.03.2021 5
EOD
$Snow <<EOD
19.02.2021 19
22.02.2021 10
04.03.2021 14
12.03.2021 8
EOD
myTimeFmt = "%d.%m.%Y"
set table $Temp
plot $Snow u (sprintf("%.0f",timecolumn(1,myTimeFmt))):2 w table
plot $Rain u (sprintf("%.0f",timecolumn(1,myTimeFmt))):2 w table
set table $SnowAndRain
set format x "%.0f"
plot $Temp u 1:2 smooth freq
unset table
set format x "%d %b" timedate
plot $SnowAndRain u 1:2 w impulses lw 4 lc "blue" title 'Snow', \
$Rain u (timecolumn(1,myTimeFmt)):2 w impulses lc "red" lw 4 title 'Rain', \
### end of script
Result:
Addition:
A bit more cumbersome solution which seem to work with gnuplot 5.0.0 (at least with Win10). I hope somebody can simplify this.
Script: (tested with Win10 gnuplot 5.0.0. Same result as above)
### "stacked" impulses (should work with gnuplot 5.0.0)
reset session
$Rain <<EOD
16.02.2021 8
22.02.2021 6
04.03.2021 10
08.03.2021 13
14.03.2021 5
EOD
$Snow <<EOD
19.02.2021 19
22.02.2021 10
04.03.2021 14
12.03.2021 8
EOD
myTimeFmt = "%d.%m.%Y"
set table $Temp
plot $Snow u (t=timecolumn(1,myTimeFmt)/1e5,int(t)):2:((t-int(t))*1e5) w table
plot $Rain u (t=timecolumn(1,myTimeFmt)/1e5,int(t)):2:((t-int(t))*1e5) w table
unset table
set table $SnowAndRain
set format x "%.0f"
plot $Temp u ($1*1e5+$3):2 smooth freq
unset table
set format x "%d %b" timedate
plot $SnowAndRain u 1:2 w impulses lw 4 lc "blue" title 'Snow', \
$Rain u (timecolumn(1,myTimeFmt)):2 w impulses lc "red" lw 4 title 'Rain'
### end of script
Impulses cannot be stacked. By definition they extend from y=0 to some non-zero y value.
If the two data sets were sampled at the same set of x coordinates then you could use the stacked histogram plot mode, but that isn't the case here.
How about back-to-back impulses rather than stacked impulses?
$RAIN << EOD
16.02.2021 8
22.02.2021 6
04.03.2021 10
08.03.2021 13
14.03.2021 5
EOD
$SNOW << EOD
19.02.2021 19
22.02.2021 10
04.03.2021 14
12.03.2021 8
EOD
set xzeroaxis
plot $RAIN using 1:2 with impulse lw 3, \
$SNOW using 1:(-$2) with impulse lw 3
I have tried to make a simplification to #theozh's answer, but some of the pulses are slightly displaced in time. #theozh has a much better solution of my problem.
reset session
$Rain <<EOD
16.02.2021 8
22.02.2021 6
04.03.2021 10
08.03.2021 13
14.03.2021 5
EOD
$Snow <<EOD
19.02.2021 19
22.02.2021 10
04.03.2021 14
12.03.2021 8
EOD
myTimeFmt = "%d.%m.%Y"
set table $Temp
plot $Snow u (timecolumn(1,myTimeFmt)):2 w table
plot $Rain u (timecolumn(1,myTimeFmt)):2 w table
unset table
set table $SnowAndRain
plot $Temp u 1:2 smooth freq
unset table
set format x "%d %b" timedate
plot $SnowAndRain u 1:2 w impulses lw 4 lc "blue" title 'Snow', \
$Rain u (timecolumn(1,myTimeFmt)):2 w impulses lc "red" lw 4 title 'Rain', \
### end of code
Addition:
The rain and snow pulses are drawn on top of each other if $Rain is written to table $RainTemp using (timecolumn(1,myTimeFmt)):2 before plotting the the graph. But still the timing is bit incorrect.
reset session
$Rain <<EOD
16.02.2021 8
22.02.2021 6
04.03.2021 10
08.03.2021 13
14.03.2021 5
EOD
$Snow <<EOD
19.02.2021 19
22.02.2021 10
04.03.2021 14
12.03.2021 8
EOD
myTimeFmt = "%d.%m.%Y"
set table $Temp
plot $Snow u (timecolumn(1,myTimeFmt)):2 w table
plot $Rain u (timecolumn(1,myTimeFmt)):2 w table
unset table
set table $SnowAndRain
plot $Temp u 1:2 smooth freq
unset table
set table $RainTemp
plot $Rain u (timecolumn(1,myTimeFmt)):2 w table
unset table
set format x "%d %b" timedate
plot $SnowAndRain u 1:2 w impulses lw 4 lc "blue" title 'Snow', \
$RainTemp u 1:2 w impulses lw 4 lc "red" title 'Rain'
I'm trying to follow the guide to plotting financial data on gnuplot found here:
http://gnuplot.sourceforge.net/demo/finance.html
I generated some data and tried plotting with the following script:
1 set datafile separator ","
2 set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb"#cccccc" behind
3
4 set xdata time
5 set timefmt "%Y-%M-%dT%H:%M:%S"
6 set format x "%d-%H"
7
8 set ylabel "Price"
9 set xlabel 'Time'
10
11 set style line 100 lt 1 lc rgb "grey" lw 0.5
12 set style line 101 lt 1 lc rgb "orange" lw 1
13
14 set grid ls 100
15 set key off
16
17 plot "lastrun.dat" using 1:2 with lines, '' using 1:3 with lines ls 101, '' using 1:4 with lines ls 101
however the resulting graph seems to not stich together the data correctly, so instead of one chart, i have three in the same space.
i'm sure i'm making a simple error but I've been stumped about what that is.
Check help time_specifiers:
%d day of the month, 01–31
%H hour, 00–23 (always two digits)
%m month, 01–12
%M minute, 0–60
%S second, integer 0–60 on output, (double) on input
%Y year, 4-digit
I have a text file as follows:
ls 10
cd 5
cut 12
awk 7
...
I would like to plot it using gnuplot with the text column as the X axis:
plot 'data.txt' u 1:2
But I get this error:
warning: Skipping data file with no valid points
^
x range is invalid
I appreciate your help
$data << EOD
ls 10
cd 5
cut 12
awk 7
EOD
# this is all just plot layout stuff; customize to taste
unset border
set tics scale 0
set xzeroaxis
set title "x coord = line number"
# use line number for x coordinate, column 1 for tic label
plot $data using 0:2:xticlabel(1) with impulse
Check help xticlabels.
And try this:
reset session
$Data <<EOD
ls 10
cd 5
cut 12
awk 7
... 9
EOD
set boxwidth 0.7
set style fill solid 1.0
set yrange[0:]
plot $Data u 2:xtic(1) w boxes
I need to do a graph with gnoplot linux where on x-axis there are a date and on y-axis value of ok, ko and warning.
I've written the following code
#!/usr/bin/gnuplot
reset
unset title
set xlabel "Date (day/month)"
set ylabel "num Instance"
set yrange [0:40]
set term png large
set output "graph2.png"
set grid
set xdata time
set timefmt "%d/%m"
set format x "%d/%m"
plot \
'input.dat' using 1:2 with points pointtype 11 linecolor rgb "#00FF00" ti 'OK',\
'input.dat' using 1:3 with points pointtype 11 linecolor rgb "#ff0000" ti 'KO',\
'input.dat' using 1:4 with points pointtype 3 linecolor rgb "#ffed00" ti 'Warning'
with this input file
#date ok ko warning
06/02 1 30 3
07/02 5 14 16
08/02 30 15 14
09/02 9 14 9
10/02 7 30 3
11/02 2 7 21
12/02 30 12 15
13/02 10 15 14
14/02 24 14 16
15/02 20 12 15
and the graph is this
new_graph
Now I've to insert, near every point, also a value of y-axis.
Any idea?
I appreciate your help and thank you in advance
I am trying to plot a graph where the x-values fall in between xtics.
For example, I want my xtics to be
C72 C73 C74 C75 C76 C77 C78 C79 C80 C81
and the points fall in between C72 C73 ; C73 C74 ; C74 C75 ; and so on.
My data points are
> 2.5 0.17509 C72
> 3.5 0.220434 C73
> 4.5 0.164918 C74
> 5.5 0.172477 C75
> 6.5 0.156145 C76
> 7.5 0.171699 C77
> 8.5 0.165199 C78
> 9.5 0.191207 C79
> 10.5 0.211656 C80
> 11.5 0.202233 C81
I used xticlabels() in the script definitions as below:
#OUTPUT
set terminal pngcairo size 650,450 enhanced dash
set output "xplot_gauche_malto-thermo.png"
set style line 4 lt 4 lw 10 # Please DISABLE pause -1
#MICRO
set macro
labelFONT="font 'arial,22'"
scaleFONT="font 'arial,18'"
scaleFONT2="font 'arial,18'"
keyFONT="font 'arial,18'"
# AXIS DEFINITIONS
set xrange [0:12]
set yrange [0:0.8]
set xtic (2,3,4,5,6,7,8,9,10,11) #scaleFONT2
set ytic #scaleFONT
set boxwidth 0.8
set size square
#PLOT
plot "all_dihedrals_in_layers_malto.dat" using 1:2:xticlabels(3) with linespoints lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title ""
If I use the code as above, to get a plot using only column 1 and 2 from data file (as given above) I get the points fall in between 2-3, 3-4, 4-5 and so on.
Unfortunately if I use "xticlabels()", I don't get the graph as I wanted where the point supposed to fall in between C72-C73, C73-C74, C74-C75 and so on.
Appreciate in advance for any help.
Thanks
try something like this.. (Untested i dont have gnuplot on this machine..)
plot "all_dihedrals_in_layers_malto.dat" using 1:2 with linespoints \
lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title "" ,\
"all_dihedrals_in_layers_malto.dat" using ($1-.5):0/0:xticlabels(3)
of course you could alternately manually key in the labels on the set xtics line..
Edit..had a chance toi try it, the 0/0 or (0/0) does not work. What you need to do is plot some value out of range.. eg:
set yrange [0:]
plot "all_dihedrals_in_layers_malto.dat" using 1:2 with linespoints \
lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title "" ,\
"all_dihedrals_in_layers_malto.dat" using ($1-.5):-1:xticlabels(3) notitle