Gnuplot - User - Error: "all points y value undefined!" - gnuplot

Here is my program. I am trying to plot data whose format looks fine to me. Gnuplot refuses to plot the data, saying that "y-values are undefined". What am I doing wrong?
set output "snowData.png"
set title "Data from Weather Station Yard"
set xdata time
set timefmt "%H:%M"
set format x "%H"
set xrange [00:24]
set xtics
set xlabel "Time(hrs)"
set ylabel "Water Content(inches)" tc lt 1
set y2label "Temperature Deg F" tc lt 2
set grid
#set yrange [0:2]
#set y2range [-20:80]
#set autoscale y2
set ytics 1 nomirror tc lt 1
set y2tics 10 nomirror tc lt 2 #MUST set y2tics to view y2label
plot "logSnow.dat" using 1:2 title "Water Content(inches)" with linespoints linetype 1,
\"logSnow.dat" using 1:3 title "Temperature" with linespoints linetype 2
Here is my data:
2019:02:20:10:55 -0.01,70.14,3.90
2019:02:20:11:26 -0.01,70.59,3.90
2019:02:20:11:57 -0.01,70.36,3.90

two issues:
your data is comma separated. So, you are missing a line
set datafile separator ","
the xrange expects a time string in the format "%H:%M"
set xrange ["00:00":"24:00"]
with this, it should work.
The following code gives the graph below (gnuplot 5.2.5):
### plotting time data
reset session
$Data <<EOD
2019:02:20:10:55,-0.01,70.14,3.90
2019:02:20:11:26,-0.01,70.59,3.90
2019:02:20:11:57,-0.01,70.36,3.90
EOD
set datafile separator ","
set xdata time
set timefmt "%Y:%m:%d:%H:%M"
set format x "%H"
set xrange ["2019:02:20:00:00":"2019:02:20:24:00"]
plot $Data u 1:2 w lp lt 1 ti "Water Content(inches)" ,\
$Data u 1:3 w lp lt 2 ti "Temperature"
### end of code

Related

How to set border setting in different colors using Gnuplot?

I am facing a small issue regarding border setting in multiplot. Though I am following a few examples available but still missing top and bottom lines.
here is the code
**
set multiplot
set border lw 2
set origin 0.05,0.49
set size 0.38,0.45
set yrange [-1.5:1.0]
set xrange [0:2.17106]
set ylabel "E-E_F (eV)" offset 0.5 font "Times-Bold, 35"
set ytics 0.5 font "Times-Bold, 35"
unset xlabel
#set title "Cubic" font "Times-Bold,35"
set label "a)" offset -1,12 font "Times-Bold,40"
plot "bands_cs.dat" using 1:($2--.3095296750) w l lc "black" lw 2 notitle, "bands_cs.dat" every :::32::32 u 1:($2--.3095296750) w l lc rgb "blue" lw 3 notitle,"bands_cs.dat" every :::33::33 u 1:($2--.3095296750) w l lc rgb "blue" lw 3 notitle,"bands_cs.dat" every :::34::34 u 1:($2--.3095296750) w l lc rgb "red" lw 3 notitle,"bands_cs.dat" every :::35::35 u 1:($2--.3095296750) w l lc rgb "red" lw 3 notitle
set origin 0.38,0.49
set size 0.14,0.483
unset arrow
unset xtics
unset label
unset yrange
unset xlabel
unset ylabel
#set xrange[0:2000]
set xtics 1000
set yrange[-1.5:1.0]
set border 1+2+4 lt rgb "black"
set title "{/Symbol s}^{AHE}(10^3 Scm^{-1}) " font "Times-Bold,25"
set key opaque box right samplen 0.8 height 1.2
xmn=-50
xmx=2500
set ytics format "" nomirror
set xtics (" " 1000,\
" " 2000 ) font "Times-Bold, 35"
set arrow from xmn, 0.0 to xmx, 0.0 nohead dt "-"
ymn=0.98
ymx=0
set arrow from 2100,-0.2 to 2100,0 nohead dt "-"
unset xlabel
#set xlabel 0,1,2
set xrange [xmn:xmx]
set y2range [0.95:1.02]
set border 8 lt rgb "dark-green" lw 2
set y2tics 0.1 nomirror textcol rgb "dark-green" font "Times-Bold, 30"
plot "cs_yx.dat" u 2:1 w l notitle ' lc rgb'black' lw 4,"strain_yx.dat" u 3:1 w lp axes x1y2 lc rgb "dark-green" lw 4 pt 7 ps 2 notitle
**
In short, i need to change one color side of the plot.
Assuming you just want to have the right y-axis of the 2nd plot in a different color (without y2tics), but the others borders in black. You can simply remove the right border via set border 5 and add a green line via set arrow.
Check help border and help margins and help arrows.
Script:
### set border in different colors
reset session
set multiplot
set margins 0,0,-1,-1 # l, r, b, t
set origin 0.10,0.10
set size 0.60,0.90
set border lw 2
set grid x,y
plot sin(x)
set origin 0.70,0.10
set size 0.20,0.90
unset ytics
set border 5 # only top and bottom
set arrow 1 from graph 1,0 to graph 1,1 lw 2 lc "green" nohead front # "manual" border
set xrange [0:10]
set xtics add ('' 0) # remove 0 label to avoid overlap with 10 of the 1st plot
plot cos(x) lc "green"
unset multiplot
### end of script
Result:
Addition: if you want to have ytics (actually, y2tics) on the right colored axis, you probably have to add a third dummy plot within the multiplot environment. Check the following example:
Script:
### set border in different colors including tics
reset session
set multiplot
set margins 0,0,-1,-1 # l, r, b, t
set origin 0.10,0.10
set size 0.60,0.90
set border lw 2
set grid x,y
plot sin(x)
set origin 0.70,0.10
set size 0.20,0.90
unset ytics
set border 5 # only top and bottom
set xrange [0:10]
set xtics add ('' 0) # remove 0 label to avoid overlap with 10 of the 1st plot
plot cos(x) lc "green"
set border 8 lw 2 lc "green"
set format x ''
set xtics scale 0
set yrange [GPVAL_Y_MIN:GPVAL_Y_MAX] # yrange from previous plot
set y2tics 0.2 nomirror
set link y2 via y inverse y
set format y2 ' '
plot NaN notitle # dummy plot, plots nothing
unset multiplot
### end of script
Result:

Adding more than one yrange on the left hand side of the plot using gnuplot

Is it possible to add more then one yrange on the left hand side of the plot using gnuplot?
See the figure linked below, please.
Ideally I would need yrange commands such as y3range, y4range, etc.
Using multiplot I could not get what I want.
set multiplot
set lmargin at scr 0.2
set bmargin at scr 0.1 # fix bottom margin
set grid
set y2range [0:20]
plot x, 2*x axes x1y2 # this is your actual plot
unset grid
set lmargin at scr 0.2
set bmargin at scr 0.15 # fix bottom margin
set yrange [0:20] # set yrange to the same as y2 in the first plot
set border 0 # switch off all borders except the left
unset xtics # switch off the stray xtics
plot -1000 notitle # plot something outside of the y(2)range
unset multi
Thank you for your help.
You have to set the yranges accordingly such that the ytics and hence the grid are nicely aligned.
Add an offset to the ytics to tune the distances. Check help xtics.
Code:
### multiple axes
reset session
# common settings for all (sub-)plots
set lmargin at screen 0.15
set bmargin at screen 0.12
set xlabel "my x-title"
set xrange[0:3000]
set grid
set ytics font ",8"
myOffsetY = 0.7
set multiplot
set ylabel "my 1st y-label" tc rgb "red" offset -2,0
set yrange [-10:6]
set ytics -10,2 tc rgb "red" offset 0,0
plot 0.001*x-10 w l lc rgb "red" notitle
set xlabel " "
unset xtics
unset grid
set ylabel "my 2nd y-label" tc rgb "green" offset 2,0
set yrange [-10.0:-2.0]
set ytics -10, 1 tc rgb "green" offset 0,-myOffsetY
set format y "%.1f"
plot 0.002*x -10w l lc rgb "green" notitle
set ylabel "my 3rd y-label" tc rgb "blue" offset -4,0
set yrange [-60:20]
set ytics -60, 10 tc rgb "blue" offset 0,myOffsetY
set format y "%.0f"
plot 0.003*x-10 w l lc rgb "blue" notitle
unset multiplot
### end of code
Result:

legends position multiplot gnuplot

I am using Windows 10 and Gnuplot 5.0.
I have a script to plot several graphs simultaneously:
GNUTERM = "wxt"
set terminal wxt
set termoption enhanced
set encoding iso_8859_1
set multiplot layout 1,3
set xtics out
set ytics out
set xtics nomirror
set ytics nomirror
set xzeroaxis linetype 2 linewidth 1.5
show xzeroaxis
# Graph1
set key center right
set xrange [3.3:9.0]
set yrange [-0.1:1.10]
set title "Title 1"
set xlabel "x"
set ylabel "y"
plot \
"results_1.dat" u 1:2:4 title "exp." with e pointtype 9 pointsize 0.5 linecolor rgb "red" , \
"results_1.dat" u 1:3 title "fit." with line linecolor rgb "black" linewidth 2 dashtype 2 smooth bezier
# Graph2
set xrange [3.3:9.0]
set yrange [-0.1:1.10]
set key top right
set title "Title 2"
set xlabel "x"
set ylabel "y"
plot \
"results_2.dat" u 1:2:4 title "exp." with e pointtype 9 pointsize 0.5 linecolor rgb "blue", \
"results_2.dat" u 1:3 title "fit." with line linecolor rgb "black" linewidth 2 dashtype 2 smooth bezier
# Graph3
set xrange [3.3:9.0]
set yrange [-0.1:1.10]
set key outside vertical top right
set title "Title 3"
set xlabel "x"
set ylabel "y
plot \
"results_3.dat" u 1:2:4 title "exp." with e pointtype 9 linecolor rgb "red", \
"results_3.dat" u 1:3 title "fit." with line linecolor rgb "black" linewidth 2 dashtype 2 smooth bezier
unset multiplot
pause 3
reread
However, instead of getting the legend outside only for the graph 3, all legends are shown outside the graphs (see attached image)
I want legends 1 and 2 inside the graphs and legend 3 outside. What's wrong in my script?
Any help is appreciated.
Supernono06
It's hard to say without being able to run your script, but if I had to guess I'd say that you request the legend to be outside for graph 3, and when you reread the script you don't put it back inside. Try something like
set key inside center top
for the first graph (or add a reset statement to the beginning of your script).

Gnuplot scatter with xticlabels and errorbars

I'm trying to do a scatter plot with Y error bars in GNUPLOT, in which the X axis are "names", not numbers.
I'm using this code:
#!/bin/sh
gnuplot -persist <<PLOT
set boxwidth 0.99 relative #ancho relativo de las barras
set border linewidth 1.5
set xlabel "xlabel" font "Verdana,18"
set xlabel offset 0,-1
#set xrange [-5:5]
set xtics font "Verdana,12"
set ylabel "ylabel" font "Verdana,18"
set ylabel offset -2,0
set yrange [-15:15]
set ytics font "Verdana,12"
set key at 4,4 font "Verdana,18"
set style line 1 lc rgb '#0060ad' pt 7 # circle
set xtics rotate by -45 #rota ángulo
plot "file.txt" using 0:2:3:xticlabels(1) with yerrorbars ls 1
quit
PLOT
As a bash script, and then the file.txt is:
Peter 3.06 0.5035
Charles 4.6576 0
Luis -13.1790 0
Where the third column is the Y error bar. However, data appears to initiate exactly in the Origin and not as usual when histogram is used...
Any clues to "shift" or set a range on X with non-numeric values?
Thank you in advance.
If you want to use autoscaling on the x-axis and just add some space to the right and left, then use set offset:
set yrange [-15:15]
set style line 1 lc rgb '#0060ad' pt 7 # circle
set xtics rotate by -45
set offset 0.5,0.5,0,0
plot "file.txt" using 0:2:3:xticlabels(1) with yerrorbars ls 1 notitle

Plot boolean values on a time based line graph

I am plotting a time based line graph and would like to add a boolean data series to it.
Is it possible to have the boolean data highlight the full height of the canvas of the graph where the value is true?
Plotfile:
set datafile separator ","
set terminal pngcairo size 800,400
set title "Solar charge monitor"
set yrange [0:]
set ylabel "V"
set y2range [0:]
set y2label "A"
set y2tics
set xlabel "Date"
set xdata time
set timefmt "%Y-%m-%dT%H:%M:%SZ"
set key left top
set grid
set output "samplePlot.png"
plot "sampleData.csv" using 1:2 with lines lw 2 title 'Batt (V)', \
"sampleData.csv" using 1:3 with lines lw 2 title 'Solar (V)', \
"sampleData.csv" using 1:4 with lines lw 2 title 'Charge (A)' axes x1y2, \
"sampleData.csv" using 1:5 with lines lw 2 title 'Load (A)' axes x1y2
Sample Data:
time,V_Batt,V_SolarV,A_Charge,A_Load,bool_charging
2014-09-25T07:06:03.358Z,13.20,14.38,0.52,0.03,1
2014-09-25T07:05:03.639Z,13.16,14.14,0.52,0.05,1
2014-09-25T07:04:02.856Z,13.18,14.19,0.54,0.03,1
2014-09-25T07:03:03.141Z,13.18,14.24,0.52,0.03,1
2014-09-25T07:02:03.410Z,13.18,14.09,0.52,0.03,1
2014-09-25T07:01:03.604Z,13.20,14.38,0.54,0.03,1
2014-09-25T07:00:02.766Z,13.11,14.28,0.50,0.02,1
2014-09-25T06:59:03.025Z,13.09,14.28,0.48,0.02,1
2014-09-25T06:58:03.302Z,13.11,14.28,0.43,0.02,1
2014-09-25T06:57:03.445Z,13.18,14.28,0.56,0.05,1
2014-09-25T06:56:02.611Z,13.16,14.14,0.52,0.03,1
2014-09-25T06:55:02.901Z,13.09,14.58,0.48,0.01,1
2014-09-25T06:54:03.178Z,13.09,14.48,0.52,0.02,1
2014-09-25T06:53:03.432Z,13.13,14.53,0.54,0.06,1
2014-09-25T06:52:03.630Z,13.11,14.28,0.48,0.03,1
2014-09-25T06:51:02.763Z,13.16,14.14,0.54,0.05,1
2014-09-25T06:50:03.068Z,13.16,14.28,0.54,0.03,1
2014-09-25T06:49:03.388Z,13.07,14.38,0.50,0.03,1
2014-09-25T06:48:02.683Z,13.09,14.33,0.50,0.03,1
2014-09-25T06:47:02.967Z,13.07,14.04,0.48,0.02,1
2014-09-25T06:46:03.249Z,13.05,14.19,0.48,0.02,1
2014-09-25T06:45:03.410Z,13.09,14.24,0.56,0.06,1
2014-09-25T06:44:02.677Z,13.07,14.24,0.52,0.03,1
2014-09-25T06:43:02.973Z,13.05,14.09,0.50,0.03,1
2014-09-25T06:42:03.282Z,13.09,14.24,0.52,0.03,1
2014-09-25T06:41:03.389Z,12.96,14.04,0.46,0.02,1
2014-09-25T06:40:02.702Z,12.76,13.59,0.50,0.00,1
I would like to add column 6 which is a boolean (0/1) value. In this sample data, the background would be fully highlighted as the bool is always true
Any tips?
You can use the boxes plotting style to draw background boxes depending on the value of column 6, i.e. something like
plot "sampleData.csv" using 1:($6 * 16) with boxes fc rgb '#ccffcc' fillstyle solid,\
"" using 1:2 lt 1 with lines lw 2 title 'Batt (V)'
That, however, requires you to know the maximum and minimum values of the y-range. If that should be calculated automatically, you'll need first to make a dummy plot with the unknown terminal and then use GPVAL_Y_MIN and GPVAL_Y_MAX:
reset
set datafile separator ","
set terminal pngcairo size 800,400
set title "Solar charge monitor"
set yrange [0:]
set ylabel "V"
set y2range [0:]
set y2label "A"
set y2tics
set xlabel "Date"
set xdata time
set timefmt "%Y-%m-%dT%H:%M:%SZ"
set key left center
set grid
set autoscale xfix
set style data lines
set terminal push
set terminal unknown
plot "sampleData.csv" using 1:2, "" using 1:3
set terminal pop
set output "samplePlot.png"
plot "sampleData.csv" using 1:(GPVAL_Y_MIN + $6 * (GPVAL_Y_MAX - GPVAL_Y_MIN)) with boxes fc rgb '#ccffcc' fillstyle solid notitle,\
"" using 1:2 lt 1 lw 2 title 'Batt (V)', \
"" using 1:3 lt 2 lw 2 title 'Solar (V)', \
"" using 1:4 lt 3 lw 2 title 'Charge (A)' axes x1y2, \
"" using 1:5 lt 4 lw 2 title 'Load (A)' axes x1y2
Using a slightly changed data file (I inserted some zeros to show the effect), I get:
If you don't want vertical lines at the boundaries, you could also use filledcurves with:
...
plot "sampleData.csv" using 1:(GPVAL_Y_MIN + $6 * (GPVAL_Y_MAX - GPVAL_Y_MIN)) with filledcurves x1 fc rgb '#ccffcc' fillstyle solid notitle,
...

Resources