Can't get gnuplot to fill below line - gnuplot

I'm trying to get gnuplot 5.0 under OS X 10.10.3 to fill blue below the lower series in this plot. I've tried lots of variations for the line dataFileForecast using 1:4 with filledcurves above y1=0 linestyle 3, but nothing seems to work.
Here's the source:
#!/opt/local/bin/gnuplot
reset
set terminal pngcairo enhanced background "#000000" font "Lato-Light,20" linewidth 1 rounded size 2048,670
set output "10DayForecast.png"
dataFileForecast = "10DayForecast.csv"
set datafile separator ','
set timefmt "%Y-%m-%d"
stats dataFileForecast using 2:4 nooutput
freezeWarning = 32.
Yhigh = STATS_max_x + 10.
Ylow = STATS_min_y - 10.
unset key
set border linetype rgb "#666666"
set boxwidth 0.25 relative
set style fill transparent solid 0.4
set style line 1 linetype rgb "#0066CC" # freeze line
set style line 2 linetype rgb "#FFFFFF" pointtype 7 pointsize .5 # points for both high and low temp
set style line 3 linetype rgb "#000077" # fill for low temp
set style line 4 linetype rgb "#FFFF00" # rain forecast
set style line 5 linetype rgb "#770000" # fill for high temp
set style line 6 linetype rgb "#FF7777" # line for high temp
set style line 7 linetype rgb "#3377FF" # line for low temp
set label "°" right
unset mxtics
set tics textcolor rgb "#666666"
# X Axis
set xdata time
set xtics format "%a" nomirror
set autoscale xfix
set offsets 12*60*60,12*60*60,0,0
# Y Axis
set yrange [Ylow:Yhigh]
unset ytics
if (32 > Ylow) set ytics 32,1,32 tc rgb "#FFFFFF" font ",18"
set ytics format "%2.0f°" nomirror
# Y2 Axis
set y2tics format "%2.0f%%" textcolor "#FFFF00" nomirror
set y2range [0:100]
plot dataFileForecast using 1:6 with impulses linestyle 4 axes x1y2,\
dataFileForecast using 1:2:4 with filledcurves above linestyle 5,\
dataFileForecast using 1:2 with lines linestyle 6,\
dataFileForecast using 1:2 with points linestyle 2,\
dataFileForecast using 1:2:3 with labels offset 1.75,0.5 textcolor "#FFFFFF" font ",18",\
dataFileForecast using 1:4 with filledcurves above y1=0 linestyle 3,\
dataFileForecast using 1:4 with lines linestyle 7,\
dataFileForecast using 1:4 with points linestyle 2,\
dataFileForecast using 1:4:5 with labels offset 1.75,0.5 textcolor "#FFFFFF" font ",18",\
freezeWarning with filledcurve above y1=0 linestyle 1
And here's a data file:
2015-06-29,94,94°,69,69°,20.0
2015-06-30,99,99°,72,72°,0.0
2015-07-01,102,102°,73,73°,0.0
2015-07-02,96,96°,69,69°,0.0
2015-07-03,94,94°,68,68°,10.0
2015-07-04,92,92°,67,67°,0.0
2015-07-05,91,91°,63,63°,0.0
2015-07-06,91,91°,62,62°,0.0
2015-07-07,91,91°,61,61°,0.0
2015-07-08,91,91°,63,63°,0.0
What am I missing?

I'm not sure, why this doesn't work. Could be a bug. As workaround you can give a third column in the using statement to indicate the lower boundary of the filled area:
plot ...,\
dataFileForecast using 1:4:(0) with filledcurves linestyle 3
This gives the output
The freezeWarning area is plotted correctly, if the yrange includes this region.

Related

How to use gnuplot to plot history graph with labels

I have two small datafiles
one
11 365.4
12 659.2
and one
11 432.1
12 882.4
I try to plot those as a histogram with labels
gnuplot <<EOF
set output 'house-energy.png'
set terminal png size 800,400 font "Arial,10"
set boxwidth 0.7 relative
set grid ytics linestyle 0
set style fill solid 0.20 border
set style data histogram
#set style histogram columnstacked
#set style histogram rowstacked
set title "Energy"
set xlabel "Month"
set ylabel "kWh"
set yrange [0:2000]
plot 'file1.dat' u 2: xtic(1) with histogram lc rgb "#0045FF" title "Energy house total", \
'' using 1:(\$2):(\$2) with labels notitle font ",10" , \
'file2.dat' u 2: xtic(1) with histogram lc rgb "#004500" title "Labb", \
'' using 1:(\$2):(\$2) with labels notitle font ",10"
EOF
But the labels are way off
Image showing plot
// GH
The histogram plotting style is implicitly using the pseudocolumn 0 (check help pseudocolumns) as x-coordinate. So, you have to place your label at column(0) or ($0) with some x-offset, e.g. ($0-0.15) in the one and other direction. And some offset in y-direction, e.g. via offset 0,0.7.
Script:
### histogram with labels
reset session
$Data1 <<EOD
11 365.4
12 659.2
EOD
$Data2 <<EOD
11 432.1
12 882.4
EOD
set boxwidth 0.7 relative
set grid ytics linestyle 0
set style fill solid 0.20 border
set style data histogram
set title "Energy"
set xlabel "Month"
set ylabel "kWh"
set yrange [0:2000]
set key noautotitle
plot $Data1 u 2:xtic(1) w histogram lc rgb "#0045FF" title "Energy house total", \
'' u ($0-0.15):2:2 w labels font ",10" offset 0,0.7, \
$Data2 u 2 w histogram lc rgb "#004500" title "Labb", \
'' u ($0+0.15):2:2 w labels font ",10" offset 0,0.7
### end of script
Result:

How to plot several Y axis in the left side using gnuplot

I am plotting same plot as from here How to plot multiple y-axes?. But also i would like them to look like in the image below. With additional lines and tics, how can i do it?
As mentioned in the answer you linked, you can plot many plots on top of each other in the multiplot environment.
So, here you are plotting 6 plots on top of each other
plot 1, 2, 3 for the data/functions
plot 4, 5, 6 for the colored axes
and plot 6 as well for the key on top of everything
In order to get the same scale for the plot and the "external" axes I would recommend to store the ranges and step sizes in the variables y10,y11,y1d, ...., such that you have to change the values only at one location.
Script:
reset session
set key opaque box noautotitle
set multiplot
set margins screen 0.3, screen 0.95, screen 0.95, screen 0.1 # l,r,t,b
# first plot
set xrange[0:10]
set xtics 2
y10 = -1.2
y11 = 1.2
y1d = 0.4
set yrange [y10:y11]
set ytics y1d
set format y '' # no ytic labels
set grid x,y
plot sin(x) lc "red"
# second plot
set border 0 # no border
unset tics # no tics
unset grid # no grid
y20 = -3.0
y21 = 3.0
y2d = 1.0
set yrange [y20:y21]
plot 3*cos(x) lc "green"
# third plot
y30 = -1.5
y31 = 1.5
y3d = 0.5
set yrange [y30:y31]
plot 3*sin(x)*cos(x) lc "blue"
# plot for axis 1
set lmargin screen 0.27
set border 2 lc "red" lw 2
set ylabel "Voltage" tc "red" offset 1.5,0
set yrange [y10:y11]
set format y
set ytics y1d nomirror
plot NaN
# plot for axis 2
set lmargin screen 0.17
set border 2 lc "green" lw 2
set ylabel "Current" tc "green" offset 0.5,0
set yrange [y20:y21]
set ytics y2d
plot NaN
# plot for axis 3 and key
set lmargin screen 0.08
set border 2 lc "blue" lw 2
set ylabel "Power" tc "blue" offset 1,0
set yrange [y30:y31]
set ytics y3d
plot NaN w l lc "red" ti "sin(x)", \
NaN w l lc "green" ti "3*cos(x)", \
NaN w l lc "blue" ti "3*sin(x)*cos(x)"
unset multiplot
### end of script
Result:

How to make xtics label color variable in box plot in GNUPlot?

This is my attempt at making the xtics label color match the line color in a box plot in gnuplot:
$DATA << EOD
1 1
2 2
3 3
EOD
set linetype 1 linecolor rgb "red"
set linetype 2 linecolor rgb "green"
set linetype 3 linecolor rgb "blue"
set key off
set boxwidth 0.5
set style fill solid 0.5
set xrange [0:4]
set yrange [0:4]
set xtics ("1" 1) textcolor rgb "red"
set xtics add ("2" 2) textcolor rgb "green"
set xtics add ("3" 3) textcolor rgb "blue"
plot $DATA using 1:2:1 with boxes linecolor variable
But it does not work:
Any idea? Thanks!
I'm not sure whether you can set xtics individually in different colors. So, the following solution sets the xtics as empty lines and you plot your xtics with labels with a certain offset. The disadvantage is that you have to set the y-position here: (0) with offset 0,-1. I hope there are better solutions.
Code:
### "xtic labels" in different colors
reset session
$Data << EOD
1 1
2 2
3 3
EOD
set linetype 1 lc "red"
set linetype 2 lc "green"
set linetype 3 lc "blue"
set key off
set boxwidth 0.5
set style fill solid 0.5
set xrange [0:4]
set yrange [0:4]
set format x "\n" # xtic label empty line
plot $Data u 1:2:1 w boxes lc var, \
'' u 1:(0):1:1 w labels tc var offset 0,-1
### end of code
Alternatively, you could use an offset relative to the graph:
plot $Data u 1:2:1 w boxes lc var, \
'' u 1:(0):1:1 w labels tc var offset 0, graph -0.05
Result:

shading plot downward with different colors

I try to plot several graphs using multiplot option in gnuplot. I use the script as shown below.
#!/usr/bin/env gnuplot
#OUTPUT
#PNG
set terminal pngcairo size 600,550 enhanced dash #font "Arial-Bold,13" #fontscale 1.20
set output "Fill-Multi-plot-LDP-lyoSystemLast50ns.png"
#############################################################################
set style line 4 lt 1 lw 2.5 lc rgb "red"
set style line 5 lt 3 lw 2.5 lc rgb "forest-green"
set style line 6 lt 5 lw 2.5 lc rgb "blue"
#############################################################################
set macro
labelFONT="font 'Arial,18'"
scaleFONT="font 'Arial-Bold,14'"
scaleFONtt="font 'Helvetica,10'"
keyFONT="font 'Arial,10'"
#############################################################################
xsize = 0.80 # change this for expand in x direction
ysize = 0.22
xorigin = 0.022
yorigin = 0.02
#############################################################################
set xrange [-25.2:25.2] noreverse nowriteback
set yrange [0:2.5] noreverse nowriteback
set xtic auto #scaleFONT # set xtics automatically
set ytic '' #0,0.2,0.4 #scaleFONT # set ytics automatically
unset key
set size 1.0,1.0
set multiplot
#############################################################################
# plot A
set ylabel ""
set label "Distance in Angstrom" at -30.0,-0.22 #labelFONT
set label "Number Density" at -58,0.70 rotate by 90 left #labelFONT
set label "(e)" at 0,0.60 #scaleFONT
set origin xorigin,yorigin
set size xsize,(ysize+0.015)
plot "bcm25perRS-251-300ns_head_tail_wat2.dat" u 1:2 w filledcurves y1=0 fs transparent solid 0.35 ls 4, \
'' u 1:3 w filledcurves fs transparent solid 0.4 ls 5,\
'' u 1:4 w filledcurves fs transparent solid 0.5 ls 6
#################################################################################
# plot B
set xrange [-25.2:25.2]
set ylabel ""
unset label
set label "(d)" at 0,0.60 #scaleFONT
set origin xorigin,(yorigin+0.19)
set size xsize,ysize+0.02
plot "bcm25perS-251-300ns_head_tail_wat2.dat" u 1:2 w filledcurves y1=0 fs transparent solid 0.35 ls 4, \
'' u 1:3 w filledcurves fs transparent solid 0.4 ls 5,\
'' u 1:4 w filledcurves fs transparent solid 0.5 ls 6
#################################################################################
## plot C
set xrange [-25.2:25.2]
set ylabel ""
unset label
set label "(c)" at 0,0.60 #scaleFONT
set origin xorigin,(yorigin+0.385)
set size xsize,ysize+0.02
plot "bcm25perR-251-300ns_head_tail_wat2.dat" u 1:2 w filledcurves y1=0 fs transparent solid 0.35 ls 4, \
'' u 1:3 w filledcurves fs transparent solid 0.4 ls 5,\
'' u 1:4 w filledcurves fs transparent solid 0.5 ls 6
#################################################################################
# plot D
set xrange [-27.3:27.3]
set xtics auto
set ylabel ""
unset label
set label "(b)" at 0,0.60 #scaleFONT
set origin xorigin,(yorigin+0.58)
set size xsize,ysize+0.02
plot "malto23per-251-300ns_head_tail_wat2.dat" u 1:2 w filledcurves y1=0 fs transparent solid 0.35 ls 4, \
'' u 1:3 w filledcurves fs transparent solid 0.4 ls 5,\
'' u 1:4 w filledcurves fs transparent solid 0.5 ls 6
#################################################################################
# plot E
set xrange [-20.0:20.0]
set xtics auto
set ylabel ""
unset label
set label "(a)" at 0,0.60 #scaleFONT
set origin xorigin,(yorigin+0.77)
set size xsize,ysize+0.02
plot "malto12per-251-300ns_head_tail_wat2.dat" u 1:2 w filledcurves y1=0 fs transparent solid 0.35 ls 4, \
'' u 1:3 w filledcurves fs transparent solid 0.4 ls 5,\
'' u 1:4 w filledcurves fs transparent solid 0.5 ls 6
#################################################################################
## plot F
set size 0.3,0.5
set origin 0.76,0.55
set bmargin at screen 0
set key center center
set border 0
unset xlabel
unset ylabel
unset label
unset tics
set format x ""
set format y ""
set yrange [0:1]
plot 2 ls 4 t 'Head', \
2 ls 5 t 'Chain', \
2 ls 6 t 'Water'
#, \
# 2 ls 10 t '151-200ns', \
# 2 ls 13 t '201-250ns', \
# 2 ls 16 t '251-300ns'
unset multiplot
Using this code I get a plot as shown here. .
The problem that I am facing here is the plot labeled (a) in the figure. The blue color shade must be downward. But it shades upward. The other figures (b), (c) and etc are correct.
The corresponding code for the figure label (a) is given in section #(PLOT E)# in the code. Especially the line for the blue shade is as follows: (u 1:4 w filledcurves fs transparent solid 0.5 ls 6).
I cannot figure out what is the mistake or error I made here.
(note: The order for the code and corresponding figures are upside down).
I appreciate any help for correcting this code. Many thanks in advance.
You want to fill the area between the curve and the lower x-axis. This is done with the option x1:
plot 'file.dat' with filledcurves x1 fs transparent solid 0.5 ls 6
I think you can set x1 for all of your areas.

Including solid and dashed contours in gnuplot

i have the following in a gnuplot script:
set pm3d
unset surface
set pm3d map
set style line 1 lt 1 lc rgb "white"
set style line 2 lt 1 lc rgb "white"
set style line 3 lt 1 lc rgb "white"
set style line 4 lt 1 lc rgb "red"
set style line 5 lt 1 lc rgb "blue"
set style line 6 lt 2 lc rgb "white"
set style line 7 lt 2 lc rgb "white"
set style line 8 lt 2 lc rgb "white"
set style line 9 lt 2 lc rgb "white"
set style increment userstyles
set contour base
set cntrparam levels 8
set cntrparam levels discrete -8*0.0004946, -6*0.0004946, -4*0.0004946, -2*0.0004946, -2*0.0004946, 4*0.0004946, 6*0.0004946, 8*0.0004946
set nokey
splot '/data/ltl21/Data/PDB/HDFNI/BlindSurvey/imageresults/spectrum/HDF1map:189.20135-62.20442' u 1:2:3
Such that, i would like to have dashed contours for negative values, and solid contours for positive values. I can change the colour of contours with the above fine, though i want them to all be white, but it doesn't seem to use lt at all, it just picks its own line style and uses that..
Does anyone know how to specify the linetype for individual contours?
Cheers
Same question just appeared to me. Here is a nice workaround I found at http://www.gnuplot.info/faq/faq.html :
gnuplot> # An example. Place your definition in the following line:
gnuplot> f(x,y) = y - x**2 / tan(y)
gnuplot> set contour base
gnuplot> set cntrparam levels discrete 0.0
gnuplot> unset surface
gnuplot> set table ’curve.dat’
gnuplot> splot f(x,y)
gnuplot> unset table
gnuplot> plot ’curve.dat’ w l
Use splot with your standard options. You can save more than one contour in one file. Each contour in the same file will be plotted in the same style.
You can set your plot options as usual: linestyle, linetype etc. That's how I used it:
gnuplot> set cntrparam levels discrete 0,1,2,3
gnuplot> set style line 1 lt 2 lw 4 lc rgb "cyan"
gnuplot> set table 'mycontours.dat'
gnuplot> splot 'mydata.dat' matrix
gnuplot> unset table
gnuplot> plot 'mycontours.dat' ls 1
It returned 4 dashed cyan contours in epslatex. It seems you need to save to different files for different contour styles (or edit the file by hand).
multiplot may be used to address this issue:
set pm3d
unset surface
set pm3d map
set view map
set key center rmargin
set dgrid3d 15,31
set hidden3d
set contour base
set nosurface
set grid lw 1 lc rgb 'gray'
f(x,y) = x*y
set nokey
set cntrparam levels discrete 2, 4, 6, 8
set linetype 1 lc rgb '#0042ad' lw 1.3
set linetype 2 lc rgb '#0060ad' lw 3.1
set linetype 3 lc rgb '#007cad' lw 31
set linetype 4 lc rgb '#0099ad' lw 0.31
set cntrlabel start 25 interval -1 font 'arial, 1'
set style textbox noborder
set multiplot
splot f(x,y) w l title ''
unset pm3d
set linetype 1 lc rgb '#00ada4' lw 2 dashtype 2
# notice how changing 'lw' or 'dashtype' does not have any effect after first use:
set linetype 2 lc rgb '#00ad88' lw 1 dashtype 1
set linetype 3 lc rgb '#00ad6b' lw 3 dashtype 4
set linetype 4 lc rgb '#eeeeee' lw 4 dashtype 3
set cntrparam levels discrete -8, -6, -4, -2
splot f(x,y) w l
unset multiplot
Unsetting pm3d is crucial or it will draw over the lines from the first splot command.

Resources