gnuplot: make only one border thicker in a surface plot - gnuplot

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...)

Related

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:

Shifting of axis title and sub-title in Gnuplot histogram

Mr data file is
# test.dat
# Sample No. Phenol Red Neutral Red Bromophenol Blue Bromocresol Green Mixed Indicator
1 80 69 223 222 130
2 89 62 321 267 160
3 92 67 248 276 147
Gnuplot code is
#
#
###
reset session
###
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 6in,4in
set output "test.eps"
#------------------------------------------------------------------------------
set style line 1 lt 4 lw 1 lc rgb "#4169E1"
set style line 2 lt 4 lw 1 lc rgb "#2E8B57"
set style line 3 lt 5 lw 1 lc rgb "#FF4500"
set style line 4 lt 4 lw 1 lc rgb "#FAD02C"
set style line 5 lt 4 lw 1 lc rgb "#FF0080"
#------------------------------------------------------------------------------
set xtics out scale 1.5
set ytics out scale 1.5
set ytics nomirror
set yrange [0:350]
set key off
set tics font ", 16"
set xlabel "Sample No. " font ",16"
set ylabel "Moisture Content ({/Symbol \155}g of H_{2}O/g of melt)" font ",16"
set key samplen 2 spacing 1.65 font ",14" width -1.0
set key inside left horizontal
set style fill solid border
set style histogram clustered gap 1 title textcolor lt -1
# ----------------------------------------
set rmargin screen 0.9
set lmargin screen 0.1
set bmargin screen 0.4
# ----------------------------------------
set style data histogram
plot \
newhistogram "Direct titration", \
'test.dat' using 2:xtic(1) ls 4 axes x1y1 title "Phenol Red", \
'' u 3 ls 5 axes x1y1 title "Neutral Red", \
newhistogram "Back-titration", \
'test.dat.dat' using 4:xtic(1) ls 1 axes x1y1 title "Bromophenol Blue", \
'' u 5 ls 2 axes x1y1 title "Bromocresol Green", \
'' u 6 ls 3 axes x1y1 title "Mixed Indicator"
# ----------------------------------------
##
Script works fine. I would like to provide more spacing between the tick labels (1,2,3) and the sub-title (Direct titration and Back-titration) as well as spacing between the sub-titles and axis title. How can it be done?
set xlabel offset 0, -1 will shift both the subtitles and the axis title downward by one character height.
set xlabel "\nTEXT" will create a two-line axis label and place TEXT on the second line.
Modifying your xlabel command to be
set xlabel "\nSample No. " font ",16" offset 0,-1
will make both those changes.

Gnuplot set background color of data label

I want to set the background of data labels to white! The considered plot is a data plot of the following data (gnuDC.dat):
4 1570.96 1571
8 770.63 771
12 530.33 530
16 385.13 385
24 261.87 262
48 137.71 138
96 81.42 81
The plot command reads:
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p ls 1, \
"gnuDC.dat" using 1:2:3 with labels center offset 2.,0.7 font "Helvetica,14" tc ls 4 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines ls 14
Which gives me:
It looks ok but think one could read the lables better when the would have an white background. Is there an easy way to add the white background for all labels at once?
Here is the whole print file:
set terminal postscript eps size 14cm,10cm enhanced color \
font 'Helvetica,18' linewidth 2
set output 'test.eps'
# Line style for axes
set style line 80 lt 0
set style line 80 lt rgb "#808080"
# Line style for grid
set style line 81 lt 3 # dashed
set style line 81 lt rgb "#808080" lw 0.5 # grey
set grid back linestyle 81
set border 3 back linestyle 80
set xtics nomirror
set ytics nomirror
set style line 100 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5
set style line 200 lc rgb '#a2142f' lt 1 lw 2 pt 7 ps 1.5
set pointintervalbox 0
set style line 1 lc rgb '#0072bd' lt 1 lw 1 pt 9 pi -10 ps 2
set style line 2 lc rgb '#77ac30' lt 1 lw 1 pt 7 pi -10 ps 2
set style line 3 lc rgb '#d95319' lt 1 lw 1 pt 1 pi -10 ps 2
set bmargin 4
set lmargin 5
set rmargin 4
unset title
set size 1,1
#set origin 0,0.27
set xlabel "number of cores, -"
set ylabel "Computational time, s"
set key top right
set key spacing 1.5
set key width -12
set yrange [0:1710]
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p ls 1, \
"gnuDC.dat" using 1:2:3 with labels center offset 2.,0.7 font "Helvetica,14" tc ls 4 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines ls 14
With gnuplot version 5 there is a boxed option which does exactly this: give labels a background and, if you want, also a border. The style is controlled with set style textbox, e.g.
set style textbox opaque noborder
plot ... with labels boxed ...
Applied to your script (with some minor changes due to the changed dash handling since 5.0):
# Line style for axes
set style line 80 lt rgb "#808080"
# Line style for grid
set style line 81 dt 3 # dashed
set style line 81 lt rgb "#808080" lw 0.5 # grey
set grid back linestyle 81
set border 3 back linestyle 80
set tics nomirror
set linetype 1 lc rgb '#0072bd' pt 9 pi -10 ps 2 dt 3
set bmargin 4
set lmargin 5
set rmargin 4
set xlabel "number of cores, -"
set ylabel "Computational time, s"
set key top right
set key spacing 1.5
set key width -12
set yrange [0:1710]
set style textbox opaque noborder
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p lt 1, \
"gnuDC.dat" using 1:2:3 with labels boxed center offset 2.,0.7 font "Helvetica,10" tc ls 1 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines lt 1
No, for versions 4.6 and earlier there isn't an easy way to achieve this.

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.

gnuplot - calculate distance between lines

Can gnuplot calculate the distance between two lines or maybe two points?
I'm having a plot where two (main) lines are plotted. For the moment let's assume that the first line is always above the second one. Is there a way to calculate the distance from line 2 to line 1 at a given x-value?
here is a picture of what my plot looks like and which distance I want to calculate:
The vertical lines are just for style and have nothing to do with the actual plot, their data is stored in test.dat and test2.dat.
My data-files of the lines look like this:
line1
0 118.1
2.754 117.77
4.054 117.64
6.131 116.17
7.7 116.04
8.391 115.36
10.535 115.25
11.433 116.03
12.591 116.22
19.519 118.59
line2
19.4 118.51
15.2 116.56
10.9 115.94
10.35 114.93
9.05 114.92
8.3 115.9
5.9 116.19
4.2 116.62
2.2 117.66
-0.3 118.06
My plotting-code looks like this:
set term wxt enhanced
cd 'working directory'
unset key
set size 0.9,0.9
set origin 0.1,0.1
set title 'TITLE'
unset border
set label 21 " rotate by 45" at -3.0,0.0 rotate by 45 point ps 2
set xrange [0:19.519]
set yrange [110:119]
set xtics nomirror(0, 2.745, 4.054, 6.131, 7.7, 8.391, 10.535, 11.433, 12.591, 19.519) rotate by 90 offset 0,-0.1 right
set ytics " ", 30000
plot "line1.dat" using ($1):($2):2 with labels offset 1, 1.8 rotate by 90, "line1.dat" using 1:2 with lines lt 1 lw 1 lc rgb '#000000', +112 lt 1 lw 1 lc rgb '#000000' , 'test.dat' with lines lt 1 lw 1 lc rgb '#000000', +110 lt 1 lw 1 lc rgb '#000000', 'line2.dat' with lines lt 0.5 lw 1 lc rgb '#000000', 'test2.dat' with lines lt 0.5 lw 1 lc rgb '#000000'
You can measure the distance manually. Move the mouse to the first point and type 'r'. Then as you move the mouse around, the x and y offsets, distance and angle are displayed. Type '5' to draw a line segment and to toggle between degrees and tangent display. Zooming in beforehand increases accuracy.
By the way, typing 'h' in the plot window will display a list of keybindings to the console.
An answer to this "rather old" question still might be of interest to OP, if not, maybe to others.
Yes, you can calculate and plot the difference of two lines. It requires some linear interpolation. Simply assign the desired x-value to the variable myX.
Data:
SO17717287_1.dat
0 118.1
2.754 117.77
4.054 117.64
6.131 116.17
7.7 116.04
8.391 115.36
10.535 115.25
11.433 116.03
12.591 116.22
19.519 118.59
SO17717287_2.dat
19.4 118.51
15.2 116.56
10.9 115.94
10.35 114.93
9.05 114.92
8.3 115.9
5.9 116.19
4.2 116.62
2.2 117.66
-0.3 118.06
Script: (works for gnuplot>=4.6.0)
### calculating and plotting a difference between two curves
reset
FILE1 = "SO17717287_1.dat"
FILE2 = "SO17717287_2.dat"
set border 1
unset key
set origin 0.05,0.05
set size 0.9,0.8
set xrange [0:19.519]
set xtics nomirror rotate by 90 offset 0,-0.1 right
set yrange [110:119]
unset ytics
myX = 15.2
getYa(xi) = (x0=x1, x1=$1, y0=y1, y1=$2, x1==xi ? ya=y1 : (sgn(x0-xi)!=sgn(x1-xi)) ? ya=(y1-y0)/(x1-x0)*(xi-x0)+y0 : NaN)
getYb(xi) = (x0=x1, x1=$1, y0=y1, y1=$2, x1==xi ? yb=y1 : (sgn(x0-xi)!=sgn(x1-xi)) ? yb=(y1-y0)/(x1-x0)*(xi-x0)+y0 : NaN)
set samples 2 # set to minimal possible value for plotting '+'
plot x1=y1=NaN FILE1 u 1:2:2:xtic(1) w labels offset 0,0.5 left rotate by 90, \
'' u 1:(getYa(myX),$2) w l lc rgb 'black', \
'' u 1:2:(0):(110-$2) w vec lt 0 nohead, \
+112 w l lc rgb 'black', \
x1=y1=NaN FILE2 u 1:(getYb(myX),$2) w l lt 0 lc rgb 'black', \
'+' u (myX):(ya):(0):(yb-ya) w vec heads lc rgb "red", \
'+' u (myX):(ya):(sprintf("%.3f",yb-ya)):xtic(sprintf("%g",myX)) w labels tc rgb "red" offset 0,1, \
'+' u (myX):(ya):(0):(110-ya) w vec nohead lt 0 lc rgb "red"
### end of script
Result: (created with gnuplot 4.6.0)

Resources