Last active
July 5, 2018 02:04
-
-
Save jenssss/67e2807989f30f9faddf3f8059102a74 to your computer and use it in GitHub Desktop.
Gnuplot script that generates a surface plot with a rasterized png part
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This gnuplot script generates a surface plot with a rasterized png part. It uses the following external utilities | |
# sed | |
# pdflatex | |
# The final output is output_base.'.pdf' | |
output_base='tan' | |
# Rendering the surface plot can be heavy, so here is a switch to not to do that part (rendersurf==1 -> surface will be rendered) | |
rendersurf=1 | |
xmax=pi*3 | |
xmin=0 | |
ymax=pi/3 | |
ymin=-ymax | |
cbran=10 | |
set ytics 1 | |
set xtics 3 | |
# Size of plot | |
tot_size_x=5 | |
tot_size_y=3 | |
png_res_factor=200 | |
pnum(x)=sprintf('%i',x) | |
set xlabel '$x$' | |
set ylabel '$y$' | |
set title 'Re$(\sin(\tan(x+iy)))$' | |
# First we produce the part of the plot that contains axes, labels and lines etc. with the cairolatex terminal | |
set term cairolatex pdf color standalone rounded size pnum(tot_size_x),pnum(tot_size_y) header\ | |
'\usepackage{amsmath}' | |
set border lw 5 lc rgb '#666666' | |
xbo=-32.8681 | |
liw=5 | |
# Colors from Colorbrewer (Google it! They have nice colors) | |
# line styles | |
set style line 1 lw liw lc rgb '#E41A1C' # red | |
set style line 2 lw liw lc rgb '#377EB8' # blue | |
set style line 3 lw liw lc rgb '#4DAF4A' # green | |
set style line 4 lw liw lc rgb '#984EA3' # purple | |
set style line 5 lw liw lc rgb '#FF7F00' # orange | |
set style line 6 lw liw lc rgb '#FFFF33' # yellow | |
set style line 7 lw liw lc rgb '#A65628' # brown | |
set style line 8 lw liw lc rgb '#F781BF' # pink | |
set output output_base.'_tex.tex' | |
set yrange [ymin:ymax] | |
set xrange [xmin:xmax] | |
bmarg=0.15 | |
tmarg=0.85 | |
lmarg=0.12 | |
rmarg=0.95 | |
set bmargin at screen bmarg | |
set tmargin at screen tmarg | |
set lmargin at screen lmarg | |
set rmargin at screen rmarg | |
plot sin(x) ls 2 notitle | |
set output | |
######################################################################################################## | |
# Now we make the surface part of the plot | |
if (rendersurf==1){ | |
print 'Starting with surf .png' | |
reset | |
set term pngcairo size pnum(tot_size_x*png_res_factor),pnum(tot_size_y*png_res_factor) transparent # | |
unset border | |
unset colorbox | |
unset title | |
unset key | |
unset ytics | |
unset xtics | |
set format x '' | |
set format y '' | |
set output output_base.'_surf.png' | |
set yrange [ymin:ymax] | |
set xrange [xmin:xmax] | |
set cbrange [-cbran:cbran] # | |
set view map | |
set bmargin at screen bmarg | |
set tmargin at screen tmarg | |
set lmargin at screen lmarg | |
set rmargin at screen rmarg | |
set palette defined ( 0 '#b2182b', 1 '#ef8a62', 2 '#fddbc7', 3 '#ffffff', 4 '#d1e5f0', 5 '#67a9cf', 6 '#2166ac') | |
unset key | |
set samples 1000 | |
set isosamples 1000 | |
splot real(sin(tan((x+y*{0,1})))) w pm3d notitle # | |
set output | |
# For some weird reason strange an edge sometimes appears if the transparent option of pngcairo is used. Instead one can use an external utility (Imagemaick) | |
# system('convert '.output_base.'.png -transparent white '.output_base.'_surf.png') # | |
print 'Done with png' # | |
} | |
# Here the string in the tex file that includes the lines is modified such that it will also include the png image we just created | |
system("sed 's|{\\\\includegraphics{".output_base."_tex-inc}}|{\\\\includegraphics[width=\\\\textwidth]{".output_base."_surf.png}}\\\\put(0,0){\\\\includegraphics[width=\\\\textwidth]{".output_base."_tex-inc.pdf}}|' ".output_base."_tex.tex > ".output_base.".tex") # | |
# Finally the pdf is generated using pdflatex | |
system('pdflatex -interaction=nonstopmode '.output_base.'.tex > pdfout.txt') | |
print 'Output in '.output_base.'.pdf' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment