Curves superimposed to a surface in gnuplot - gnuplot

I am trying to create a plot with gnuplot where some curves are superimposed to a surface.
This is the code I use
#!/usr/bin/gnuplot
xwidth=16.2
set size 1,1
set terminal epslatex color size xwidth cm,0.59*xwidth font 9 header '\fontsize{10}{13.2} \usepackage[lite,subscriptcorrection,slantedGreek,nofontinfo]{mtpro2}\usepackage{amsmath} \renewcommand{\rmdefault}{ptm}' dashlength 2.0 round standalone
set output "Pernal12.tex"
set border 0 lw 0
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
set multiplot
####
set size 0.55,1.166
set origin 0.02,-0.035
set xrange [0:10]
set yrange [-6:6]
set zrange [0:10]
unset ylabel
unset xlabel
set format y ''
set format x ''
unset xtics
unset ytics
unset label
set view map
set isosamples 400, 400
set style data pm3d
set style function pm3d
set pm3d implicit at b
#set grid noxtics noytics noztics front
#set palette positive nops_allcF maxcolors 0 gamma 1.5 gray
set palette defined (0 "white", 10 "black")
set pm3d interpolate 1,1
spacing 1.1
set cbrange[0:10]
unset colorbox
t={1,0}
e0={1,0}
eta={0.1,0}
i={0.0,1.0}
c(x)=sqrt(16*t**2+x**2)
a(x)=sqrt(2*((4*t/(c(x)-x))**2+1))
A(x)=(1-4*t/(c(x)-x))**2
B(x)=(1+4*t/(c(x)-x))**2
Gbup(x,y)=1/a(x)**2*(A(x)/(y-(e0+t+(c(x)+x)/2)+x/2+1+i*eta)+B(x)/(y-(e0+t-(c(x)-x)/2)+x /2+1+i*eta))
Gaup(x,y)=1/a(x)**2*(B(x)/(y-(e0-t+(c(x)+x)/2)+x/2+1+i*eta)+A(x)/(y-(e0-t-(c(x)-x)/2)+x/2+1+i*eta))
splot -imag(Gbup(x,y)+Gaup(x,y))/1.01 notitle
####
unset border
set border 15 lw 1
set size 0.385,0.83
set origin 0.087,0.11
unset xtics
unset ytics
set xrange [0:10]
set yrange [-6:6]
set zrange [0:20]
set xlabel '$U/t$'
set ylabel '$\omega/t$' offset 1.0,0
set xtics 5.0
set mxtics 5
set label '$n = 1/2$' left at graph 0,1 offset 2.2,-1.6 front
set xtics ("0" 0,"" 1 1,"" 2 1,"" 3 1,"" 4 1, '5' 5,"" 6 1,"" 7 1,"" 8 1,"" 9 1, '10' 10)
set ytics ( '-6' 6,"" 5 1,"-4" 4,"" 3 1,"-2" 2,"" 1 1, "0" 0,"" -1 1,"2" -2,"" -3 1,"4" -4, "" -5 1, "6" -6)
set grid noxtics noytics noztics front
plot 'Pernal12sym.dat' u ($1):(-$8) w l lw 2.5 lc rgb "green" lt 2 notitle
q
I obtain a nice figure but the problem is its dimension, more than 10 Mb.
I could reduce the isosamples value but then the surface map resolution would be too low.
Is there a way to obtain a quite high resolution with a final .ps file whith a dimension under let's say 1Mb?
I also tried to save before the surface map in png and than using this script
#!/usr/bin/gnuplot
xwidth=16.2
set size 1,1
set terminal epslatex color size xwidth cm,0.59*xwidth font 9 header '\fontsize{10}{13.2} \usepackage[lite,subscriptcorrection,slantedGreek,nofontinfo]{mtpro2}\usepackage{amsmath} \renewcommand{\rmdefault}{ptm}\usepackage{graphicx}' dashlength 2.0 round standalone
set output "Pernal12.tex"
set border 0 lw 0
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
set multiplot
####
set size 0.55,1.166
set origin 0.02,-0.035
set xrange [0:10]
set yrange [-6:6]
set zrange [0:10]
unset ylabel
unset xlabel
set format y ''
set format x ''
unset xtics
unset ytics
unset label
plot "Pernal13.png" binary filetype=png w rgbimage
unset border
set border 15 lw 1
set size 0.385,0.83
set origin 0.087,0.11
unset xtics
unset ytics
set xrange [0:10]
set yrange [-6:6]
set zrange [0:20]
set xlabel '$U/t$'
set ylabel '$\omega/t$' offset 1.0,0
set xtics 5.0
set mxtics 5
set grid noxtics noytics noztics front
plot 'Pernal12sym.dat' u ($1):(-$8) w l lw 2.5 lc rgb "green" lt 2 notitle
q
But at the end I don't have my .png image as the background of the .ps file.

For that kind of plots (equidistant sampling in x- and y-directions) it is worth using the image plotting style. Since I don't have the data file to test the whole script, here is the first part using plot '++' ... with image instead of splot ... with pm3d:
xwidth=16.2
set terminal epslatex color size xwidth cm,0.59*xwidth font 9 dashlength 2.0 round standalone
set output "Pernal12.tex"
unset border
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
set multiplot
####
set size 0.55,1.166
set origin 0.02,-0.035
set xrange [0:10]
set yrange [-6:6]
set zrange [0:10]
unset tics
set view map
set samples 1000
set isosamples 1000, 1000
set palette defined (0 "white", 10 "black")
set cbrange[0:10]
unset colorbox
t={1,0}
e0={1,0}
eta={0.1,0}
i={0.0,1.0}
c(x)=sqrt(16*t**2+x**2)
a(x)=sqrt(2*((4*t/(c(x)-x))**2+1))
A(x)=(1-4*t/(c(x)-x))**2
B(x)=(1+4*t/(c(x)-x))**2
Gbup(x,y)=1/a(x)**2*(A(x)/(y-(e0+t+(c(x)+x)/2)+x/2+1+i*eta)+B(x)/(y-(e0+t-(c(x)-x)/2)+x /2+1+i*eta))
Gaup(x,y)=1/a(x)**2*(B(x)/(y-(e0-t+(c(x)+x)/2)+x/2+1+i*eta)+A(x)/(y-(e0-t-(c(x)-x)/2)+x/2+1+i*eta))
plot '++' using 1:2:(-imag(Gbup($1,$2)+Gaup($1,$2))/1.01) with image notitle
The resulting .ps file is 938kB big. If you have the change to use the 5.0rc2 version, you can get down to 106kB with the level3 terminal option.
BTW: It is quite pointless to use set size and set origin and also set all margins with set lmargin, bmargin, tmargin and rmargin. See also Big data surface plots: Call gnuplot from tikz to generate bitmap and include automatically?.

Related

Setting the size of title in gnuplot

I have the following script to place in a bash script:
#!/bin/bash
set -e
gnuplot -persist <<-EOFMarker
set pixmap 1 "pathToimage/fig.png" at screen 0.85, 0 width screen 0.15 behind
set rmargin at screen 0.85
# Border line definition
set border lw 1
# Major and Minor grid definition
set style line 100 lt 1 lc rgb "gray" lw 2
set style line 101 lt 0.5 lc rgb "gray" lw 1
set grid mytics ytics ls 100, ls 101
set grid mxtics xtics ls 100, ls 101
set title 'myTitle' font ", 30"
set ylabel 'y [m]' font "Helvetica, 12"
set xlabel 'x [m]' font "Helvetica, 12"
set tics font "Helvetica,10"
plot [-10:10] sin(x),atan(x),cos(atan(x))
EOFMarker
The script is intended to do some plotting and place a logo on the corner of the plot. However, I am not able to change the size of the fonts... I am using gnuplot 5.4.3.
Any advice?
Have you tried to set a terminal? Maybe your default terminal does not support changing the title size.
Using this script, I can set the title size:
set pixmap 1 "linux.png" at screen 0.85, 0 width screen 0.15 behind
set rmargin at screen 0.85
# Border line definition
set border lw 1
# Major and Minor grid definition
set style line 100 lt 1 lc rgb "gray" lw 2
set style line 101 lt 0.5 lc rgb "gray" lw 1
set grid mytics ytics ls 100, ls 101
set grid mxtics xtics ls 100, ls 101
set term png # new
set o "output.png" # new
set title 'myTitle' font ", 30"
set ylabel 'y [m]' font ", 12" # removed font spec
set xlabel 'x [m]' font ", 12" # removed font spec
set tics font ",10"
plot [-10:10] sin(x),atan(x),cos(atan(x))
set o
The output is
If I set the font size to 12, I get

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

Plotting histogram+linespoints in Gnuplot

I would like to connect selected bars in a histogram with linespoints. Now
I have created the histogram using the following code in Gnuplot:
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 6in,4in
set output "LS_Figure_Histogram_New_2019_III.eps"
set xtics out scale 1.5
set ytics out scale 1.5
set y2tics out scale 1.5
set ytics nomirror
set yrange [-3.50:-3.70]
set y2range [0:45]
set key off
set tics font ", 14"
set xlabel "Experiment No." font ",16"
set ylabel "Li^{+}|Li vs. Cl^{-}|Cl_{2} (V)" font ",16"
set y2label "Residual Current Density (mA/cm^{2})" font ",16"
set key autotitle columnheader
set key inside left horizontal
set style fill solid 1.00 noborder
set style histogram clustered gap 1 title textcolor lt -1
set style data histograms
plot 'LS_Histogram_Comp_2019.dat' using 2:xtic(1) ls 2 ti col axis x1y1, '' u 3:xticlabels(1) ls 4 ti col axis x1y2
The data file is as given below
# Histogram_Comparison of onset potential & Residual current density
Experimental "Li^{+}|Li (V)" "Res. Current Density (mA/cm^{2})"
1 -3.64469 31.3
2 -3.65257 11.2
3 -3.66159 32.39
4 -3.66536 13.41
5 -3.66314 16.3
6 -3.64556 10.3
7 -3.64383 10.08
8 -3.63042 9.96
9 -3.65344 9.59
10 -3.64383 8.44
11 -3.64859 11.1
12 -3.63919 27.6
13 -3.64204 9.78
14 -3.62692 30.96
15 -3.64348 18.22
16 -3.6362 32.05
17 -3.62831 20.1
18 -3.62984 42.32
19 -3.63764 24.8
I wish to connect bars corresponding to Experimental 12, 14, 16 and 18 (using col 1 and 3 data) and bars 13, 15, 17 and 19 (using col 1 and 3 data) using linespoints.
Is there a way to do it in Gnuplot?
Try this
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 6in,4in
set output "LS_Figure_Histogram_New_2019_III.eps"
set xtics out scale 1.5
set ytics out scale 1.5
set y2tics out scale 1.5
set ytics nomirror
set yrange [-3.50:-3.70]
set y2range [0:45]
set key off
set tics font ", 14"
set xlabel "Experiment No." font ",16"
set ylabel "Li^{+}|Li vs. Cl^{-}|Cl_{2} (V)" font ",16"
set y2label "Residual Current Density (mA/cm^{2})" font ",16"
set key autotitle columnheader
set key inside left horizontal
set style fill solid 1.00 noborder
set style histogram clustered gap 1 title textcolor lt -1
# ----------------------------------------
set rmargin screen 0.9
set lmargin screen 0.1
set bmargin screen 0.1
set multiplot
# ----------------------------------------
set style data histograms
plot 'LS_Histogram_Comp_2019.dat' using 2:xtic(1) ls 2 ti col axis x1y1, '' u 3:xticlabels(1) ls 4 ti col axis x1y2
# ----------------------------------------
unset tics
unset xlabel
unset ylabel
unset y2label
set xrange [0:20]
set yrange [0:45]
plot 'LS_Histogram_Comp_2019.dat' \
skip 12 every 2 using 1:3 w linespoints ls 1 lw 4 not,\
'' skip 13 every 2 using 1:3 w linespoints ls 3 lw 4 not
The result

gnuplot epslatex terminal problematic dvi or ps output

I am using the epslatex terminal to generate eps figures with gnuplot 4.6.4.
However, I am having problem with this script
# reset
reset
#
sz = 1.4
rx = 10.0/7.0
#
set style line 1 lt 1 pointsize 1
# blue line
set style line 2 lt 12 pointsize 1
#
set terminal epslatex size rx*sz,2*sz color standalone
set output 'output.tex'
set multiplot layout 2,2
# Figure 1,1
set tmargin 0
set bmargin 0
set lmargin at screen 0.05
set rmargin at screen 0.475
set format x ""
set xrange [30:130]
set ylabel offset 2,0 "Y label [sec]"
unset xlabel
set grid
set yrange [0:9]
set ytics ("" 0, "1" 1, "2" 2, "3" 3, "4" 4, \
"5" 5, "6" 6, "7" 7, "8" 8, "" 9)
unset key
plot "./inp" u 1:2 t "tsL" w lp ls 1, \
"" u 1:3 t "vL" w lp ls 2
#
# Figure 1,2
set bmargin 0
set tmargin 0
set lmargin at screen 0.525
set rmargin at screen 0.95
set format x ""
set format y ""
set xrange [30:130]
set yrange [0:9]
#set mytics 2
unset ylabel
unset xlabel
set grid
plot "./inp" u 1:2 t "tsL" w lp ls 1, \
"" u 1:3 t "vL" w lp ls 2
# Figure 2,1
set tmargin 0
set bmargin 0
set lmargin at screen 0.05
set rmargin at screen 0.475
set format x "%g"
set format y "%g"
set xrange [30:130]
set ylabel offset 2,0 "Ylabel"
set xlabel offset 0,0.6 "neig"
set grid
set yrange [0:9]
set ytics ("" 0, "1" 1, "2" 2, "3" 3, "4" 4, \
"5" 5, "6" 6, "7" 7, "8" 8, "" 9)
unset key
set xtics ("40" 40, "" 60 , "80" 80,\
"" 100, "120" 120)
set mxtics 2
plot "./inp" u 1:2 t "tsL" w lp ls 1, \
"" u 1:3 t "vL" w lp ls 2
#
# Figure 2,2
set bmargin 0
set tmargin 0
set lmargin at screen 0.525
set rmargin at screen 0.95
set format y ""
set format x "%g"
set xrange [30:130]
set yrange [0:9]
#set ylabel "Ylabel"
unset ylabel
set xlabel offset 0,0.6 "neig"
set grid
set xtics ("40" 40, "" 60 , "80" 80,\
"" 100, "120" 120)
set mxtics 2
plot "./inp" u 1:2 t "tsL" w lp ls 1, \
"" u 1:3 t "vL" w lp ls 2
#
unset multiplot
#
set output
with the input file inp which includes
40 1 3
60 2 4
80 3 5
100 4 6
120 5 7
If I compile the document, everything goes fine. However, there is a line missing in dvi file and the labels seem to be at wrong location. After that, if I execute "dvips output.dvi", I get a completely wrong ps output without any labels and ytics at the wrong location. What is my mistake with this implementation?
The dvi output is usually wrong, especially the labels, because these are typeset with Postscript operations, which aren't interpreted correctly by many dvi viewers.
Concerning the labels, your left margins are too small, so that the labels are outside of the image. For you example I had to use
set lmargin at screen 0.2
set ylabel offset 0.5,0 "Y label [sec]"
for Figure 1,1 in order to have reasonable margins and see all labels (ytic labels and ylabel). The ytics are ok.
In the same manner you have to fix the other settings of lmargin and rmargin of the other subfigures, and also the bmargin of the bottom row in order to see the xlabel and the xtic labels.
And you don't need to set the ytics manually. Use
set ytics 1,1,8 # tics from 1 to 8 in steps of 1
set xtics 40 # distance of 40 between tics.
Margins and plot area
Some remarks about the margins, plot area and canvas size.
The image size (i.e. the canvas size) is given by the size terminal option (e.g. set terminal pngcairo size 800,400).
Usually, the size and position of the plotting area inside the canvas is determined automatically based on several points:
Font size
Presence and position of xlabel, ylabel etc, title, key being outside, colorbox, length of tic labels and so on.
The plotting area can be changed relative to the automatically determined one by set size and set origin (and for splot it can be scaled with set view).
The plotting area can also be set fixed by specifying explicit margins. In this case the user has to care about providing large enough margins to fit in all the elements. The margins can be specified independently with set lmargin, set rmargin, set bmargin and set tmargin. Their values can be specified in two ways:
set tmargin 1 leaves a top margin equivalent to one character height.
set tmargin at screen 0.95 leaves a top margin of 5% of the total canvas size.

How can I add specified color to 2-d curve in 3-d plot in Gnuplot?

I had a working code as follows:
set term postscript eps enhanced color
set output "C:\\Users\\cole1\\Desktop\\gnuplot_w1.eps"
set multiplot
set isosamples 140
unset key
set title "r"
set xrange [-6:6]
set yrange [-6:6]
set zrange [-4:4]
set hidden3d nooffset
# set style arrow 1 lw 2 head filled size 0.1,20,70
unset key
# set ztics 1
set view 69,120 #Done implicitly by mousing.
# set arrow 1 nohead from 0,0,0 to 0,0,4.0 as 1 back
# set arrow 2 nohead from 0,0,0 to 0,4.5,0 as 1 back
# set arrow 3 nohead from 0,0,0 to 4.5,0,0 as 1 back
splot (x**2+y**2+1)**(0.5),-(x**2+y**2+1)**(0.5)
# set arrow 4 nohead from 0,0,2.5 to 0,0,4.0 as 1 front
unset xtics
unset ytics
unset ztics
set parametric
set samples 1000
plot 0.1*sin(25*t)-1,0.1*cos(25*t)-0.5 lw 1
plot 0.06*sin(25*t)-1.25,0.06*cos(25*t)+2.75 lw 3
unset xtics
unset ytics
unset multiplot
I then tried to make the first curve appear green by changing that line (fifth-last line above) to
plot 0.1*sin(25*t)-1,0.1*cos(25*t)-0.5 lw 1 ; rgb "green"
and it gives me an invalid command error. How can I solve this problem?
You need to use the linecolor command
plot 0.1*sin(25*t)-1,0.1*cos(25*t)-0.5 lw 1 lc rgb "green"

Resources