shading plot downward with different colors - gnuplot

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.

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 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:

How to manage tick lable and axis-lable in gnu multiplot

I have two files each is having five columns where 1st will be the x-axis in both the data.
I want to make a multiplot 2 2 in GNU with zero spacing.
I could manage many things but I am could not fix below problems:
1. How to place the figure at the center of the page i.e. equal left right margin? I set the left, right, top and bottom margin but it is not working.
2. How to number the figure. For example, Figure 1 1 should be numbered as (a), figure 1 2 should be numbered as (b) and so on.
3. How to put tick lable and tick mark on the plot 1 2 and 2 2 on right side of the plot?
4. how to create a common title at the bottom of the figure representing the X-axis.
I have tried to make gnu multiplot layout but still it is not giving desired results. The script I used is mentioned below:
My code is
[![set terminal postscript eps enhanced size 20cm,15cm color solid lw 3 "Times-Roman" 24
reset
set lmargin screen 0.10
set rmargin screen 0.95
set bmargin screen 0.15
set tmargin screen 0.9
set mxtics 2
set mytics 2
set tics font "Times-bold, 50"
set output "absorption.pdf"
set multiplot layout 2,2 margin 0.2, 0.9, 0.1, 0.9 spacing 0.00, 0.00
set tics scale 1.2
set tics font "Times-bold, 26"
set key spacing 1.2
unset key
set xrange \[0:8.5\]
set yrange \[0:1\]
set xlabel ' '
set format x ""
set ylabel 'A11' font 'Times-bold, 26' offset 1,1,3
unset label
plot "data1.dat" u 1:($2/10**4) w l lw 3 lt 2 lc rgb "red" title "x-D", 'data1.dat' u 1:($3/10**4) w l lw 3 lc rgb "blue" title "z-D"
unset label
unset format x
unset key
set key inside center top # to adjust the legends position
set xrange \[0:8.5\]
set yrange \[0:1\]
set title ' '
set xlabel ' '
set xlabel ' '
set format x ""
set ylabel ' '
set format y " "
set key spacing 1.2
set ylabel 'A12' font 'Times-bold, 26' offset 1,0,3
plot "data1.dat" u 1:($4/10**2) w l lw 3 lt 2 lc rgb "red" title "x-D", 'data1.dat' u 1:($5/10**2) w l lw 3 lt 2 lc rgb "blue" title "Z-D"
unset label
unset format y
unset format x
unset key
set xrange \[0:8.5\]
set yrange \[0:1.08\]
set xlabel ' '
unset label
set ylabel 'A21' font 'Times-bold, 28'
unset label
plot "data2.dat" u 1:($2/10) w l lw 3 lt 2 lc rgb "red" title "x-dir", 'data2.dat' u 1:($4/10) w l lw 3 lt 2 lc rgb "blue" title "z-dir" ,\
unset label
unset format x
unset key
set xrange \[0:8.5\]
set yrange \[0:1.08\]
set title ' '
set format y ""
set xlabel 'X-12-scale' font 'Times-bold, 28'
set ylabel 'A22' font 'Times-bold, 28'
plot "data2.dat" u 1:($3/10) w l lw 3 lt 2 lc rgb "red" title "x-dir", 'data2.dat' u 1:($5/10) w l lw 3 lt 2 lc rgb "blue" title "z-dir"
unset label
unset format y
unset key
unset multiplot
set output][1]][1]
My data should be like what I want according to attached figure queries and hand marks.
Try this
reset
set encoding utf8
set terminal pngcairo size 750,500 font ",10"
set output "Multiplot_2x2.png"
set multiplot \
layout 2,2 rowsfirst \
title "{/:Bold=11 Multiplot 2×2}" \
margins screen 0.10,0.92,0.12,0.90 \
spacing screen 0.00,0.00
set link y2
# Gaussian fuction
f(x,a,b,c) = a*exp(-((x-b)/c)**2)
# Parameters to first one
a1 = 0.95
b1 = 4.00
c1 = 1.00
# Parameters to second one
a2 = 0.95
b2 = 5.00
c2 = 1.00
# Line style
set style line 1 lc "#e41a1c" # red
set style line 2 lc "#377eb8" # blue
# -----------------------------------------------
set xrange [0:10]
set yrange [0:1.0]
set xtics format ""
set ytics
set ylabel "y-label"
set label 1 "{/:Bold (a)}" at graph 0.05, 0.9
plot f(x,a1,b1,c1) w l ls 1 notitle, f(x,a2,b2,c2) w l ls 2 notitle
# -----------------------------------------------
unset ylabel
set ytics format ""
set y2tics format ""
set y2label "y2-label"
set label 1 "{/:Bold (b)}"
plot f(x,a1,b1,c1) w l ls 1 title "Your title 1", f(x,a2,b2,c2) w l ls 2 title "Your title 2"
# -----------------------------------------------
unset y2tics
unset y2label
set xtics 0,2,9 format "%g"
set ytics 0,0.2,0.9 format "%g"
set ylabel "y-label"
set label 1 "{/:Bold (c)}"
plot f(x,a1,b1,c1) w l ls 1 notitle, f(x,a2,b2,c2) w l ls 2 notitle
# -----------------------------------------------
unset ylabel
set xtics 0,2,10
set xlabel "common x-label" offset screen -0.20,0.0
set ytics format ""
set y2tics
set y2label "y2-label"
set label 1 "{/:Bold (d)}"
plot f(x,a1,b1,c1) w l ls 1 notitle, f(x,a2,b2,c2) w l ls 2 notitle
# -----------------------------------------------
Result

gnuplot: make only one border thicker in a surface plot

So I am trying to plot a three-dimensional sphere on the first quadrant like this --
I want to make the line BC thicker/bold from the rest. How do I do that?
This is my gnuplot script:
set term wxt 0
set parametric
set urange[0:0.5 * pi]
set vrange[0:0.5 * pi]
r = 1
fx(v,u) = r * cos(v) * cos(u)
fy(v,u) = r * sin(u) * cos(v)
fz(v) = r * sin(v)
set label 1 "A" font "Arial, 15" front at 0.000, 0.900, -0.050
set label 2 "B" font "Arial, 15" front at 0.050, 0.000, 0.900
set label 3 "C" font "Arial, 15" front at 1.050, 0.105, 0.000
set pm3d depthorder border linetype 1 linewidth 0.50
set style fill transparent solid 0.50 border
set palette
set hidden3d
unset colorbox
splot fx(u,v), fy(u,v), fz(u) w pm3d, \
"< echo '0.000 0.000 1.000'" with points pt 7 ps 0.75 lc rgb 'black', \
"< echo '0.000 1.000 0.000'" with points pt 7 ps 0.75 lc rgb 'black', \
"< echo '1.000 0.000 0.000'" with points pt 7 ps 0.75 lc rgb 'black'
set term push
set term pdf enhanced mono
set output "b1.pdf"
replot
unset output
set term pop
system(sprintf("%s", "pdfcrop b1.pdf b1.pdf"))
well, simply plot the line B,C again with lines.
And what is this line in parametric representation? fx(u,0), fy(0,0), fz(u)
splot fx(u,v), fy(u,v), fz(u) w pm3d, \
fx(u,0), fy(0,0), fz(u) w l lw 3 lc rgb "red"
Which gives you something like this... (well, different terminal...)

Can't get gnuplot to fill below line

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.

Resources